sleepingsquirrel has asked for the wisdom of the Perl Monks concerning the following question:
...and get rid of the my $tmp...for my $tmp ("a","b","c") { for (1,2,3) { print "$tmp, $_\n"; } }
And on a related note, is there a way to force a closure to bind particular instances of @_ to its creators @_? Example...for ("a","b","c") { for (1,2,3) { print "$__, $_\n"; } }
...replace with...sub test { # return a closure to a routine which prints the creator's # first argument and the closure's first argument. my $val=$_[0]; sub { print "$val, $_[0]\n" } }
sub test2 { sub { print "BLANK $_[0]\n" } # ^ # fill in the BLANK with something that refers to # test2's $_[0], not the anonymous sub's }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $_, one lexical scope removed
by dave_the_m (Monsignor) on Jul 15, 2004 at 18:13 UTC | |
|
Re: $_, one lexical scope removed
by BrowserUk (Patriarch) on Jul 15, 2004 at 23:10 UTC | |
|
Re: $_, one lexical scope removed
by perrin (Chancellor) on Jul 15, 2004 at 18:42 UTC | |
by sleepingsquirrel (Chaplain) on Jul 15, 2004 at 19:49 UTC | |
by revdiablo (Prior) on Jul 15, 2004 at 20:59 UTC | |
|
Re: $_, one lexical scope removed
by TomDLux (Vicar) on Jul 15, 2004 at 19:16 UTC | |
by sleepingsquirrel (Chaplain) on Jul 15, 2004 at 20:11 UTC | |
|
Re: $_, one lexical scope removed
by jeffa (Bishop) on Jul 16, 2004 at 14:45 UTC |