he probably want to keep the order of the keys, not sort in ascending order... if he reads the file later, he won't know which number represents which value.
compare the 2 lines of output :
use strict;
my %stats=('sent',0,
'recv',4,
'masters',2,
'errors',2
);
my @saveorder = qw (sent recv masters errors);
print join (",", @stats{@saveorder}), "\n",
join(',', sort { $a <=> $b } values %stats), "\n";
The first one will print out in the order specified in @saveorder, so you know which item comes where in your list. The second is just sorted, which could make for unpredictability later on in life...
See also storable, but that's probably overkill here.
Update : Almost forgot - jaspersan, take a look in perldata for array slices or hash slices.
| [reply] [Watch: Dir/Any] [d/l] |
| [reply] [Watch: Dir/Any] |