Created
May 24, 2011 19:43
Lexical vars in a closure
This file contains hidden or 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/env perl | |
use warnings; | |
use strict; | |
{ | |
my %hsh = map { ($_ => 1) } qw( some costy hashmap here ); | |
sub has { | |
return $hsh{$_[0]}; | |
} | |
}; | |
print has('costy'), "\n"; | |
print has('hash'), "\n"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Subs are "global", i.e. kept in package symbol table, which you can manipulate during runtime, e.g.