Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Reading in a dumped hash reference works in the perl debugger but not in the code.

by Ken Slater (Initiate)
on Mar 15, 2012 at 17:06 UTC ( [id://959821]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://959821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found