Anonymous functions
#!/usr/bin/perl
use warnings;
use strict;
my $productRef = sub
{
my $product = 1;
foreach ( @_ ) {
$product *= $_;
}
return $product;
};
my $printVal = &$productRef( 1, 2, 3, 4 );
print( join( ' * ', 1, 2, 3, 4 ), " = " );
print( "$printVal\n" );
Related examples in the same category