Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: foreach-loop-local var in sub

by LanX (Bishop)
on Jan 22, 2013 at 18:20 UTC ( #1014756=note: print w/replies, xml ) Need Help??


in reply to Re^3: foreach-loop-local var in sub
in thread foreach-loop-local var in sub

> I'm looking forward to my subs!

no need to wait it's just another syntax for my $sub =sub {}, just w/o the need to do dereferencing and occupying a scalar variable.

from Re: foreach-loop-local var in sub:

use strict; use warnings; foreach (0, 1) { my $i = $_; my $print = sub { print $i; }; $print->(); # 0,1 }

Cheers Rolf

Replies are listed 'Best First'.
Re^5: foreach-loop-local var in sub
by muba (Priest) on Jan 22, 2013 at 19:36 UTC

    Which is what I use all the time now ;) But it feels kinda hacky, even though it works and even though it's actually documented behaviour. Getting "real" lexically scoped subroutines would feel less work-aroundish.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014756]
help
Chatterbox?
[marto]: My German is very limited and Google translate really isn't helping with that one :P
[erix]: my "Jeschwätz von jestern" = "Geschwätz von gestern" = "my babbling of yesterday"

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2018-01-19 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (218 votes). Check out past polls.

    Notices?