++. I do not deny that there are multiple of fully-functional ways around the issue, and seeing so many of the TIMTOWTDI is one of the many things that draws me to PM, even though the vast bulk of my programming is not in Perl. I was pointing this out as a reasonable circumstance in which one might expect the loop variable to persist. And, like morgon expressed, it is counter-intuitive to me that my $nCond; for $nCond (1 .. 10) and my $nCond; for($nCond=1; $nCond<=10; ++$nCond) would behave differently w/r/t localization of $nCond. But every language has it's own unique character, and that's fine.

If I needed this construct in Perl, I would have eventually settled either on my alternative or this more c-like one... But likely my own alternative: over the last couple years of regularly participating here, my mindset has changed from c-like for-loops to perlish ones, so the c-for idiom is no longer my first (or often even second) choice. And, once I was reminded of the auto-localization in foreach(), I probably would have assumed auto-localization in for(;;), and wouldn't've even tried it.


In reply to Re^4: loop surprise by pryrt
in thread loop surprise by morgon

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.