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

Re^2: why need my in a foreach loop?

by szabgab (Priest)
on Nov 28, 2010 at 18:33 UTC ( #874127=note: print w/ replies, xml ) Need Help??


in reply to Re: why need my in a foreach loop?
in thread why need my in a foreach loop?

apparently most people thought here I don't understand that use strict (or more specifically the 'vars' part of it) forces the need of "my". My question why do we need that in a for-loop.

As you also know way better than I, Perl 6 can get by without this. I don't see when does that "my" do any useful work there. It is not the "my" that defines the scope of this variable so IMHO it is there only to satisfy "use strict".


Comment on Re^2: why need my in a foreach loop?
Re^3: why need my in a foreach loop?
by TomDLux (Vicar) on Nov 29, 2010 at 04:27 UTC

    I love that in Perl6 loops automatically create localized variables: (may look familiar to Gabor)

    for @names -> $n { say $n; }

    Why not backport that feature into Perl5. Maybe only if warnings and strict and features are full on.<?p>

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Re^3: why need my in a foreach loop?
by chromatic (Archbishop) on Nov 29, 2010 at 06:18 UTC
    It is not the "my" that defines the scope of this variable so IMHO it is there only to satisfy "use strict".

    I can't think of any other cases in which Perl 5 automatically lexicalizes a named variable without my; I think it's a (useful) consistency.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-09-30 11:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (363 votes), past polls