Created
July 27, 2010 03:25
-
-
Save aklaswad/491673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
## In sort method, generated sub routine can't access to the lexical variables | |
## of outer scope... | |
use strict; | |
use warnings; | |
sub my_sort ($$) { | |
my ( $a, $b ) = @_; | |
my $foo = 1; | |
my $code = sub { | |
return $foo; | |
}; | |
my $res = $code->() || 0; | |
print STDERR ( $foo == $res ? "Match\n" : "Not Match\n" ); | |
return $a <=> $b; | |
} | |
print STDERR "Just call it\n"; | |
my_sort(1,2); # prints "Match" | |
print STDERR "Called from sort method\n"; | |
my @sorted = sort my_sort (1,2); # but this prints "Not Match"... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment