programming-examples/perl/Subroutine/Anonymous functions.pl
2019-11-15 12:59:38 +01:00

21 lines
292 B
Perl

#!/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" );