in reply to Re^2: Why Does the Hash Seem Empty?
in thread Why Does the Hash Seem Empty?
From perldoc -f each:
========================
When the hash is entirely read, a null array is returned in list context (which when assigned produces a false (0) value), and "undef" in scalar context. The next call to "each" after that will start iterating again. There is a single iterator for each hash, shared by all "each", "keys", and "values" function calls in the program; it can be reset by reading all the elements from the hash, or by evaluating "keys HASH" or "values HASH". If you add or delete elements of a hash while you're iterating over it, you may get entries skipped or duplicated, so don't.
========================
So, it's a function of the way that each is designed at a lower level -- to preserve iterator locations unless keys or values is re-run, most likely a similar methodology to the way C's strtok(2) works by first specifying the target string, then being able to specify NULL for the first arg and picking up where you last left off.
|
|---|