<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 06/22/2012 01:36 PM, Fulko Hew wrote:
<blockquote
cite="mid:CAGuV3hMqeYYaUriD93mUNehkyK-Y3ffuF90czToNdB1JD2kd3g@mail.gmail.com"
type="cite"><font face="courier new,monospace">I have a
mysteriously disappearing hash...<br>
<br>
If I look at it (in advance) it contains stuff,<br>
but if I just 'use' it, then its empty... Schrodinger's ghost?<br>
<br>
<br>
I have the following fragment:<br>
<br>
...<br>
#print "varbindTable num keys: ", scalar keys %varbindTable,
"\n";<br>
while (($index, $object) = each %varbindTable) {<br>
... do loopy stuff ...<br>
}<br>
<br>
If I enable the print statement and run my code, the hash
'contains stuff'.<br>
but if I comment it out, the while loop is skipped.<br>
</font><br>
</blockquote>
i feel this has something to do with the internal iterator of the
hash. try calling keys again in void context as that will reset the
iterator:<br>
<br>
As a side effect, calling keys() resets the HASH's
internal<br>
iterator (see "each"). In particular, calling keys()
in void<br>
context resets the iterator with no other overhead.<br>
<br>
somehow the first call to keys is iterating through and leaving it
at the end of the hash (yes, end of found keys!). then the each call
fails as you can see. a reset via keys should fix it. dunno why the
scalar keys call leaves it in that state.<br>
<br>
uri<br>
<br>
<br>
</body>
</html>