[Omaha.pm] Pulling in a hash via "exec"...FAIL

Dan Linder dan at linder.org
Wed Aug 6 15:08:58 PDT 2008


I've got one program that generates a hash and then uses Data::Dump to write
this structure to a text file:
printf FILE Data::Dumper->Dump(\%fields],['fields']);

The resulting file contains this:
--- begin contents ---
$fields = {
  'FIELD1' => {
                 FIRSTNAME => 'Joe',
                 LASTNAME => 'Smith'
  }
}
--- end contents ---

Unfortunately, when I try to use "eval" to pull this hash variable construct
into a second running process:
--- begin contents ---
sub retrieve_fields {
        my ( $file )=@_;
        my %fields;
        open(FILE, $file)
        {
                local $/;
                eval <FILE>;
        }
        return %fields;
}
--- end contents ---

When I run the second program, perl dies on the "eval" line with this error:
Variable "$fields" is not imported at (eval 125)[testprog.pl:33] line 1,
<FILE> chunk 1.

The odd thing is if the Data::Dump file is changed to "%fields = ( ... )"
then the "eval" works!?!?

I've found some notes about using "our" and "use vars qw(...)".  Anyone else
have any suggestions?

Dan

-- 
"Quis custodiet ipsos custodes?" (Who can watch the watchmen?) -- from the
Satires of Juvenal
"I do not fear computers, I fear the lack of them." -- Isaac Asimov (Author)
** *** ***** ******* *********** *************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20080806/1e017e52/attachment.html>


More information about the Omaha-pm mailing list