Wrong how? By suggesting that foreach() could work if suitably innovated? I don't see how this could be wrong. You are looking at the current implementation of foreach() and local() and declaring it impossible, unfeasible, or wrong. If everybody looked at Perl this way, there would be no Perl 6, let alone Perl 2.

Please note that I didn't say the patch would be less than 100 lines long. Perl's evolution is entirely based on this sort of principle. People expecting something to 'just work'. It doesn't. People fix it so that it does. This is Perl. You should be familiar with this by now. :-)

You seem to be stuck on the definition of 'variable'. Where you and the original poster differ is that you don't see a[5] as a variable. I and the original poster *do* consider a[5] to be a variable. Fine, it doesn't have a simple name, but then, who cares about simple names? Your example showing that local() has a wider scope is wrong, since I am sure you should realize that:

package main; local $b = 2; $main::b = 3; print "$b\n"; # prints "3\n"

Meaning, that '$b' is really just ${$main::{'b'}}, which is just as much a 'variable' or not a 'variable' as $a[5] is.

I think I've made my case... :-)


In reply to Re: Re: Re: Re: Re: Re: Surpised by foreach iterator limitation by MarkM
in thread Surpised by foreach iterator limitation by shotgunefx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.