in reply to Data Dumper Examples

If you change the line where you dump the data structure to
print N Dumper(\%dict);
You can load the dumped hash with a simple do e.g
my $dict = do "cide.$alpha[$a].pl" or die "Couldn't load dump: $!, $@";
This will load the hashref that was dumped into $dict.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Data Dumper Examples
by cranberry13 (Beadle) on Nov 03, 2003 at 11:37 UTC
    Broquaint -- I am using the 'do' command as you suggested, but when I try to retrieve a value, it comes out empty. I think the problems is that is doesn't recongnise the %dict hash. I tried using %VAR1 and it didn't work either. Any suggestions?
    ## testing to see if the 'do' command worked: my $dict = do "a.pl" or die "could not load for reading: $!, $@"; my $test = $dict{'anode'}{def}; print "test: $test\n";
      Make certain you're dumping a single value. This is because do is evaluating the file and returning the last thing evaluated, which in the case of a single dumped hashref should be the hashref itself e.g
      shell> perl -MData::Dumper -e 'my %h = qw/foo bar baz quux/; print Dumper \%h' > h.dump shell> cat h.dump $VAR1 = { 'foo' => 'bar', 'baz' => 'quux' }; shell> perl -MData::Dumper -e 'my $h = do "h.dump"; print Dumper $h' $VAR1 = { 'foo' => 'bar', 'baz' => 'quux' };
      Note that I'm using a hash ref there, not a hash. You'll also want to turn on $Data::Dumper::Terse if you're running with strict 'vars' as it'll choke on $VAR1.
      HTH

      _________
      broquaint