in reply to Re: Saving Hash Values to file
in thread Saving Hash Values to file

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.

Replies are listed 'Best First'.
Re: Re: Re: Saving Hash Values to file
by tachyon (Chancellor) on May 07, 2002 at 06:07 UTC

    If you want to store and retreve a hash then why not use dbmopen?

    Storable is worth discovering too?