theguvnor has asked for the wisdom of the Perl Monks concerning the following question:
I have been trying to eval a text file that I previously dumped to file with Data::Dumper. I had no luck until I lifted stricture with a no strict.
Could someone explain this to a very tired monk? I'm sure there is solid logical reason for it, but the diagnostics message wasn't making particularly much sense to me after a full day in front of the screen.
Update: never mind, I see now. Because use strict; doesn't like the undeclared $VAR1 from the file, the assignment fails. I didn't see this earlier but I see this now by adding a print $@ if $@; right after the eval(). Like I said, I'm tired ;-) Thanks to the swift replies that confirmed this (silly) oversight on my part.
Here's (the original) reduced problemset:
use strict; use diagnostics; my $h; # hashref { #no strict; # no output until un-commented!! local $/; my $t=<DATA>; $h=eval $t; } foreach my $item ( keys %{$h} ) { print "$item\n"; } exit; __DATA__ $VAR1 = { 'ITEM1' => { 'A' => { 'count' => 4, 'percentage' => '1', 'qty' => 4 } }, 'ITEM2' => { 'A' => { 'count' => 15, 'percentage' => '1', 'qty' => 193 } } };
[Jon]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recreating hash from Data::Dumper text
by kvale (Monsignor) on Apr 14, 2004 at 21:50 UTC | |
|
Re: Recreating hash from Data::Dumper text
by Stevie-O (Friar) on Apr 14, 2004 at 22:02 UTC | |
by PodMaster (Abbot) on Apr 15, 2004 at 06:36 UTC | |
by theguvnor (Chaplain) on Apr 15, 2004 at 19:29 UTC | |
|
Re: Recreating hash from Data::Dumper text
by tilly (Archbishop) on Apr 15, 2004 at 02:34 UTC | |
|
Re: Recreating hash from Data::Dumper text
by Stevie-O (Friar) on Apr 14, 2004 at 21:46 UTC | |
|
Re: Recreating hash from Data::Dumper text
by Plankton (Vicar) on Apr 14, 2004 at 22:24 UTC |