| Richard Proctor 2005-06-08, 9:04 pm |
| On Thu 19 Jun, Colin Foster wrote:
> Hi All,
>
> Is there a way of saving hashes to a file and then retrieving them from
> the file?
>
> Colin.
>
There are 1001+ ways but a simple way is:
To save:
foreach (keys %hash) { print FILE "$_=$hash{$_}\n" }
To read:
while (<FILE> ) {
chomp;
($k,$v) = split /=/;
$hash{$k} = $v;
}
I leave the opening and closing of the FILE to the reader. If the hash
value contains binary data and/or multiple lines then encode/decode
the value in some suitable form, likewise for the key if necessary.
Richard
--
Personal Richard@waveney.org http://www.waveney.org
Telecoms Richard@WaveneyConsulting.com http://www.WaveneyConsulting.com
Web services Richard@wavwebs.com http://www.wavwebs.com
Independent Telecomms Specialist, ATM expert, Web Analyst & Services
|