http://www.perlmonks.org?node_id=1014578


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

I'm looking forward to my subs!

Replies are listed 'Best First'.
Re^4: foreach-loop-local var in sub
by LanX (Saint) on Jan 22, 2013 at 18:20 UTC
    > 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

      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.