in reply to Accessing variables in an external hash without eval

@hashdata should really be a scalar.
This simplifies the code (It could be similified even more if you did not need to expand into @dereferencedData):
use strict; use warnings; use Data::Dumper; my %hash; my $loadedFile = do {local $/=undef; <DATA>}; { no strict; eval ($loadedFile); if ($@) {print 'eval error:'.$@."\n"; } } my $hashData = $hash{Scope}{model}; my @dereferencedData = @$hashData; print "Data: \n", Dumper (\@dereferencedData), "\n"; __DATA__ %hash = ( #scope changes Scope => { model => [ 'data I need', 'another row of needed data', 'more data I need' ] }, IrreleventScope =>{ a=>'b' } );
Output:
Data: $VAR1 = [ 'data I need', 'another row of needed data', 'more data I need' ];

                Once it hits the fan, the only rational choice is to sweep it up, package it, and sell it as fertilizer.

Replies are listed 'Best First'.
Re^2: Accessing variables in an external hash without eval
by victorz22 (Sexton) on May 17, 2017 at 05:08 UTC

    Thanks for the tip on using a scalar instead of an array. I still can't get the code to work, the error i get is that $hashData doesn't get initialized so there is something wrong with that call, however $loadedFile does get loaded in properly, thank you.

      Show us the offending line(s) of code, and the data you are working with, and, most importantly, the error message!

                      Once it hits the fan, the only rational choice is to sweep it up, package it, and sell it as fertilizer.