NAME ^

t/php/closures.t - testing closures

SYNOPSIS ^

    perl t/harness t/php/closures.t

DESCRIPTION ^

Defining and calling closures.

my $anon_no_args = sub () { print "The function anon_no_args() has been called.\n"; };

$anon_no_args();

my $anon_one_arg = sub ($arg_1) { print "'$arg_1' was passed to anon_one_arg().\n"; };

$anon_one_arg('one');

sub gen_indentor ( $indention ) {

    my $indentor = sub ($line) {
        print $indention ~ $line ~ "\n";
    };

    return $indentor;
}

my $sub_1 = gen_indentor(' '); my $sub_2 = gen_indentor(' '); my $sub_3 = gen_indentor(' ');

$sub_1('1a'); $sub_1('1b'); $sub_1('1c'); $sub_2('2a'); $sub_2('2b'); $sub_2('2c'); $sub_3('3a'); $sub_3('3b'); $sub_3('3c');


parrot