A closure is an anonymous subroutine : Closure « Subroutine « Perl






A closure is an anonymous subroutine

   

my $name="Tommy";
{   my $name = "Tom";  
    my $age = 6;
    $ref = sub{ return "$name is $age.\n"; }
}
print "$name is back\n";
print &{$ref};

   
    
    
  








Related examples in the same category

1.Closure in action
2.Using closures.