#!/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? There are still elements in the list...? # Also, in the case of longer hashes, wouldn't the while be more efficient? 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"; }