in reply to Use of Hash For Table Lookup
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'/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Use of Hash For Table Lookup
by country1 (Acolyte) on Aug 17, 2007 at 14:31 UTC | |
by blazar (Canon) on Aug 17, 2007 at 16:37 UTC | |
by xorl (Deacon) on Aug 20, 2007 at 13:08 UTC |