But actually, you probably don't care what the each state at
the
end of your loop is. You care about the state at the
beginning, so you will know
that you potentially process all elements. And these two
are only the same if you only use each inside loops.
However, it's perfectly ok to have code like:
# Suppose I know the hash has at least two entries, and
# it's freshly restarted
# Process first entry
my($tag, $val) = each %hash) ;
do_something($tag, $val);
#Process second entry
($tag, $val) = each %hash;
do_something($tag, $val);
more_processing();
No loop here, so I don't suppose you would want to change
the each semantics here.
But now suppose more_processing calls your while loop
using each, which can also be called from other points in
the program. You will still have the problem of not knowing
the state, even with your proposed modification to the
semantics of loops/each. So you'd have to reset the hash
anyways.
So in short, I don't think your proposal would make the
use of each easier, while the current sometimes useful behaviour would be lost. So all in all your proposal would be a loss.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.