#!/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";
}
Thanks,
Alex
Edit by tye to replace PRE tags around long lines with CODE tags