Data::Dumper does everything that you're trying to achieve:
use Data::Dumper; my %users = ( me => 1, you => 2, others => 3 ); #dump hash to file open my $file, ">", "temp~" or die $!; print $file Dumper \%users; close $file; #read hash data from file open $file, "<", "temp~" or die $!; my $hash_data = do { local $/; <$file> }; close $file; #eval it into %hash my %hash = do { no strict 'vars'; %{ eval $hash_data } }; print Dumper \%hash;
Output:
$VAR1 = { 'you' => 2, 'others' => 3, 'me' => 1 };
Have a good look at Data::Dumper. Other people have other favorites, but I think it's the third most useful module there is. strict and warnings being the top two, of course.
update: s/my $VAR1/no strict 'vars'/
In reply to Re: Use of Hash For Table Lookup
by FunkyMonk
in thread Use of Hash For Table Lookup
by country1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |