Using closures. : Closure « Subroutine « Perl






Using closures.

   
#!/usr/bin/perl 
sub errorMsg { 
    my $lvl = shift; 
    
    return sub { 
        my $msg = shift; 
        print "Err Level $lvl:$msg\n";
    };
} 
$severe = errorMsg("Severe"); 
&$severe("Divide by zero"); 

   
    
    
  








Related examples in the same category

1.Closure in action
2.A closure is an anonymous subroutine