If you use the wonderful Data::Dumper module, it's very simple to save and restore your data structures from a file. For example:
use strict; use warnings; use Data::Dumper; our $phash = { "enabled" => "true", "honorold" => "true", "debug" => "false", "questsfull" => "false", "tooltipshtml" => "true", "lite" => "true", "scan" => { "inventory" => "true", "talents" => "true", "honor" => "true", "reputation" => "true", "spells" => "true", "pet" => "true", "equipment" => "true", "professions" => "true", "mail" => "true", "skills" => "true", "quests" => "true", "bank" => "true", }, "ver" => "10500", "reagenthtml" => "true", "talentsfull" => "true", }; # Save to a file my $fh; my $fname = "data.txt"; open($fh, ">", $fname) or die "Cannot write to '$fname' ($!)\n"; my $d = Data::Dumper->new([$phash], ['phash']); print $fh $d->Dump(); close $fh; + # Time passes ... # Make the hash null, to verify that it's read from the file correctly $phash = 0; printf "Results of hash = %s\n", Dumper($phash); + # Read back the file do $fname; printf "Results of hash = %s\n", Dumper($phash);
Note the usage of our $phash, so that the $phash = ... in the output file will be in the same scope as the version of $phash which is in the script.
In reply to Re: Help with making a string into a hash
by liverpole
in thread Help with making a string into a hash
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |