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


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

Replies are listed 'Best First'.
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.

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.