To answer your question about resetting a hash to access one of its key value pairs...that could be interpreted in a variety of ways.
Restting a hash i usually interpret as:
%my_hash = ();
Which would delete all the key-value pairs, which i highly doubt is what you want.

You are probably thinking of the key iterator needing to be reset. When you traverse the keys in a hash using keys, each, or values, the hashes internal iterator is used to keep track of what key to return next. There is only 1 iterator in a hash, not 1 for each type of operation. But, generally you dont need to worry about this if you are using keys or values, becuase they always iterate through the hash all at once, although it may not look like that in your program. (more details can be found in various docs)

When you use each though, only the *next* key / value pair is returned, and the iterator is somewhere in the *middle* of the key list. So if you have a loop using each and it exits before traversing the entire hash, the iterator will not be put back to the start of the key list. This is the only time that you would generally need to reset the iterator. One way to do this is simply:
keys %myhash;
That may be more info than you wanted. But accessing a key or value in a hash has nothing to do with the key iterator.

That said, if you do add or delete keys during a loop, you may get some unexpected behaviour in the loop.

In reply to Re: hashes by shemp
in thread Detect and reset hashes by Anonymous Monk

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.