For those who teased out the various pitfalls and solutions i thank you!
I have solved it, my biggest pitfall was incorrectly passing data to the sub and trying to call the fLoadModules sub from another sub and main.
As seen in the thread, indeed the most convenient way is to dump the data into an array and return it like so.
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;
}
And in main() I have taken the argument via command line for the path to the folder containing the file needed.
my $modules_path = $opts{e};
Next I pass $module_path to the sub which will call the other sub (to retrieve the list from the file)
fCompose $dbh, $modules_path;
Finally from within that sub I can call fLoadModules to obtain the data I need.
sub fCompose {
my($dbh, $modules_path) = @_;
my @retstr = fLoadModules($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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.