in reply to Accessing variables in an external hash without eval
As kevbot said your example is flawed.
This works for me
Resultuse strict; use warnings; use Data::Dumper; my %hash; my $loadedFile = join "", <DATA>; { no strict; eval ($loadedFile); if ($@) {print 'eval error:'.$@."\n"; } } my @hashData = $hash{Scope}{model}; my @dereferencedData; foreach my $line (@hashData){ @dereferencedData = @$line; } print "Data: \n"; print Dumper @dereferencedData; print "\n"; __DATA__ %hash = ( #scope changes Scope => { model => [ 1,2,3,4,5,6 ] }, IrreleventScope =>{ a=>'b' } ) ;
Notice the addition of a semi to the end of your example dataData: $VAR1 = 1; $VAR2 = 2; $VAR3 = 3; $VAR4 = 4; $VAR5 = 5; $VAR6 = 6;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Accessing variables in an external hash without eval
by victorz22 (Sexton) on May 17, 2017 at 05:12 UTC | |
by Laurent_R (Canon) on May 17, 2017 at 06:10 UTC | |
by marinersk (Priest) on May 18, 2017 at 02:13 UTC |