in reply to While on hashes doesn't work?
Simply put because while doesn't work like that :)
Explicitly, while doesn't iterate over the items of a list in the way that for does and it doesn't set $_ unless the expression is the diamond operator.
To get your example to work with while you will need to do something like :
my @foo = sort (keys %data); while( $_ = shift @foo ) { print "while: $data{$_}\n"; }
/J\
|
|---|