in reply to Perl variable scoping between functions
And in main() I have taken the argument via command line for the path to the folder containing the file needed.sub fLoadModules { my ($modules) = @_; my @array; open my $fh, "<", $modules or die "Couldn't open module file: $mod +ules"; while(<$fh>) { chomp; my ($module_id) = split /;/; push @array, $module_id; } close $fh; return @array; }
Next I pass $module_path to the sub which will call the other sub (to retrieve the list from the file)my $modules_path = $opts{e};
Finally from within that sub I can call fLoadModules to obtain the data I need.fCompose $dbh, $modules_path;
So for clarity, this was the issue and how it was rectified. Thank you once again to the contributors, it is as always a big help when its needed!sub fCompose { my($dbh, $modules_path) = @_; my @retstr = fLoadModules($modules_path); .... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl variable scoping between functions
by tobyink (Canon) on Jul 20, 2018 at 13:04 UTC |