Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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

by tobyink (Abbot)
on Jan 21, 2013 at 16:57 UTC ( #1014497=note: print w/ replies, xml ) Need Help??

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

FYI, Perl 5.18 will have experimental implementations of my sub, state sub and our sub. our sub is effectively the same as the existing sub keyword but can also be used to hide my sub subs, a la:

use 5.010; our $foo = 42; my $foo = 99; say $foo; # says 99 our $foo; # "hides" my $foo say $foo; # says 42
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Comment on Re^2: foreach-loop-local var in sub
Select or Download Code
Replies are listed 'Best First'.
Re^3: foreach-loop-local var in sub
by muba (Priest) on Jan 22, 2013 at 06:23 UTC

    I'm looking forward to my subs!

      > 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014497]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2015-11-25 06:24 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (671 votes), past polls