rovf has asked for the wisdom of the Perl Monks concerning the following question:
The following loop does not terminate:
The idea here is to denote the hash verbatim, without introducing a new variable, but this doesn't work. I believe the reason is that on each the hash constructed anew, and $r never advances to the next element. Of course I could code it like this:# endless loop here while(my ($r,$s) = each(%{ {x=>5,y=>8}})) { print($r); };
(or don't use references at all), but my question is: Is it possible to code this loop without naming the hash?# this works my $h={x=>5,y=>8}; while(my ($r,$s) = each(%{ $h })) { print($r); };
--
Ronald Fischer <ynnor@mm.st>
Ronald Fischer <ynnor@mm.st>
Back to
Seekers of Perl Wisdom