blahblah has asked for the wisdom of the Perl Monks concerning the following question:
Thanks,#!/usr/sbin/perl -w use strict; use diagnostics; # QUESTION: # Why does the for loop execute and the while loop does not? # Obviously the while conditional is not evaluating true, but why? The +re are still elements in the list...? # Also, in the case of longer hashes, wouldn't the while be more effic +ient? my %data = ( a01 => "two", a02 => "peas", a03 => "in", a04 => "a", a05 => "pod." ); for (sort (keys %data)) { print "for: $data{$_}\n"; } while (sort (keys %data)) { print "while: $data{$_}\n"; }
Edit by tye to replace PRE tags around long lines with CODE tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: While on hashes doesn't work?
by gellyfish (Monsignor) on Feb 04, 2002 at 22:27 UTC | |
|
Re: While on hashes doesn't work?
by mkmcconn (Chaplain) on Feb 04, 2002 at 23:26 UTC | |
by merlyn (Sage) on Feb 04, 2002 at 23:38 UTC |