in reply to Reading in a dumped hash reference works in the perl debugger but not in the code.

Not sure if I have enough info, but the following seems to work for me on Windows XP, ActiveState Perl 5.8.9.

use strict; use warnings; use Data::Dumper; my $filename = 'hashref.txt'; my $hashRef = {a => '1', b => '2'}; open my $FH, '>', $filename or die "Unable to open $filename for output: $^E\n"; print $FH Dumper $hashRef; close $FH; my $testdata; # Since I'm using 'strict', must declare $VAR1 as it is used in # the dump file. my $VAR1; open $FH, '<', $filename or die $!; { local $/; # Not sure what this line is for # $DB::single=1; $testdata = eval <$FH>; } close $FH; while (my ($key,$value) = each(%$testdata)) { print "$key $value\n"; } # # This is what the file hashref.txt looks loke # __DATA__ $VAR1 = { 'a' => '1', 'b' => '2' };

HTH, Ken

  • Comment on Re: Reading in a dumped hash reference works in the perl debugger but not in the code.
  • Download Code

Replies are listed 'Best First'.
Re^2: Reading in a dumped hash reference works in the perl debugger but not in the code.
by Anonymous Monk on Mar 15, 2012 at 18:00 UTC

    Thanks Ken. Unfortunately $testdata is still undefined when I use your code to read in my file. What's strange is that the dumped file seems perfectly valid. If I take a copy of the dumped data from the file and paste it into the code and compare it against the hash generated before it's dumped it works just fine.