in reply to Fun with arrays and hashes
2 & 3. A hash is not ordered, so there is no way to access the 'first' element. However, the keys( %hash ) function returns an array of the keys of a hash. This array is not ordered and calling keys repeatedly may or may not yield the same results. A common construct is to sort the keys before looping over the array; this will step through the hash in the alpabetical order of the keys, which is nearly but not really the same thing you are asking for in 2)
for my $key ( sort keys %myhash ) { print "$key: $myhash($key)\n"; }
Cheers,
--Moodster
|
|---|