SPUG: each() on hashref giving INFINITE LOOP!
Doug Beaver
dougb at scalar.org
Fri Jan 21 18:29:44 CST 2000
On Fri, Jan 21, 2000 at 03:32:45PM -0800, Tim Maher/CONSULTIX wrote:
> The following program, a simple demo for passing and using a hash-ref, is
> getting an infinite loop when using while(each) in the sub, but not
> when using foreach there! Can anybody shed some light on this?
You're not doing the while loop correctly:
> $i=0; # sense and break out of infinite loop!
> while ( ($key,$value) = %$hashref ) {
> print "$key -> $value\n";
> $i++; # break out of infinite loop
> $i > 3 and die "\tInfinite Loop Terminated!\n";
> }
That should be:
while (($key, $value) = each %$hashref) {
Doug
--
Smithers: I'm afraid we have a bad image, Sir. Market research shows
people see you as somewhat of an ogre.
Burns: I ought to club them and eat their bones!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list
mailing list