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!
In reply to Data::Dumper and eval by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |