SPUG: each() on hashref giving INFINITE LOOP!

Tim Maher/CONSULTIX tim at consultix-inc.com
Fri Jan 21 18:41:34 CST 2000


On Fri, Jan 21, 2000 at 04:29:44PM -0800, Doug Beaver wrote:
> 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) {

The each() was there at one time, I swear it!  But it did get lost along
the way, and I couldn't spot my mistake.

Thanks!
-Tim

> 
> 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!

-- 
*========================================================================*
| Tim Maher, PhD  Consultix &              (206) 781-UNIX/8649           |
|  Pacific Software Gurus, Inc             Email: tim at consultix-inc.com  |
|  UNIX/Linux & Perl Training              http://www.consultix-inc.com  |
| 2/22: UNIX  2/28: Perl Modules  2/29: Int. Perl  3/3: Pattern Matching |
*========================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    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