Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
When the script is rerun, it initializes that hash by reading the file:print DATA Dumper( \%somehash );
This works fine, but sometimes the datafile is empty. When that happens, I get the following message:open DATA, "<$datafile" or die "$!"; { local $/; %somehash = %{ eval <DATA> }; }
I tried to put the eval in a block to trap it:Can't use an undefined value as a HASH reference at somescript.pl line + 22, <DATA> chunk 1.
Unfortunately, I then get the following error message:%somehash = %{ eval { <DATA> } };
Anyone know how I can work around this? I thought about putting an empty {} in the file, but it would be nice to know what I'm doing wrong with the eval.Ambiguous use of %{eval{...}} resolved to %eval{...} at somescript.pl +line 22. Global symbol "%eval" requires explicit package name at somescript.pl +line 22. syntax error at somescript.pl line 22, near "%{ eval { " syntax error at somescript.pl line 23, near "}" Execution of somescript.pl aborted due to compilation errors.
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Data::Dumper and eval
by chromatic (Archbishop) on Nov 28, 2000 at 05:40 UTC | |
Re: Data::Dumper and eval
by merlyn (Sage) on Nov 28, 2000 at 08:09 UTC | |
(tye)Re: Data::Dumper and eval
by tye (Sage) on Nov 28, 2000 at 05:56 UTC | |
Re (tilly) 1: Data::Dumper and eval
by tilly (Archbishop) on Nov 28, 2000 at 07:06 UTC | |
Re: Data::Dumper and eval
by rpc (Monk) on Nov 28, 2000 at 05:31 UTC | |
Re: Data::Dumper and eval
by cwest (Friar) on Nov 28, 2000 at 05:28 UTC |