in reply to Accessing variables in an external hash without eval
Hello victorz22,
I tried using eval...
Actually, this is a job for the do EXPR syntax (see do). With data file dir/hash_file.txt under the script’s directory and its contents corrected as per kevbot’s answer, the following script:
use strict; use warnings; use Data::Dumper; our %hash; cycleUsesForLibs('./dir', 'Scope', 'hash_file.txt', 'model'); sub cycleUsesForLibs { my ($fileDirectory, $scopeName, $fileName, $modelName) = @_; chdir $fileDirectory; do $fileName; my @hashData = $hash{$scopeName}{$modelName}; my @dereferencedData; push @dereferencedData, @$_ for @hashData; print "Data: \n", Dumper(@dereferencedData); }
gives this output:
14:35 >perl 1777_SoPW.pl Data: $VAR1 = 'data I need'; $VAR2 = 'another row of needed data'; $VAR3 = 'more data I need'; 14:36 >
Note:
Hope that helps,
Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Accessing variables in an external hash without eval
by victorz22 (Sexton) on May 17, 2017 at 05:27 UTC | |
by Athanasius (Archbishop) on May 17, 2017 at 05:50 UTC |