Perl_Ally has asked for the wisdom of the Perl Monks concerning the following question:
Hello!
Help greatly appreciated.
I have the following code:
sub extractData { my @projects; push( @projects, [readOnly("$proj Data.txt"), "A"] ); unless( $pointerProj eq "NONE" ) { push( @projects, [readOnly("$pointerProj Data.txt"), "B"] ); } for( @projects ) { my @data = @{ $_[0] }; my $key = $_[1]; ... } } sub readOnly { my @contents; my $filePath; my $file; my $errMsg; $filePath = "$path\\" . $_[0]; $errMsg = "Unable to read $filePath: $!"; open $file, '<', $filePath or die $errMsg; @contents = <$file>; close $file; return @contents; }
My problem is that I'm not correctly passing the resultant array from readOnly() through the anon array pushed in to @projects to ultimately store and use it as @data inside the for-loop.
The error message I'm getting is "Can't use an undefined value as an ARRAY reference at (the first line inside the for-loop)".
If someone could provide me with the correct syntax and the rationale behind it I would be much obliged.
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Passing Along Arrays
by frozenwithjoy (Priest) on Aug 26, 2014 at 20:35 UTC | |
by Perl_Ally (Novice) on Aug 26, 2014 at 20:54 UTC | |
by frozenwithjoy (Priest) on Aug 26, 2014 at 21:02 UTC | |
by Perl_Ally (Novice) on Aug 26, 2014 at 21:14 UTC | |
by Perl_Ally (Novice) on Aug 26, 2014 at 21:36 UTC | |
by frozenwithjoy (Priest) on Aug 26, 2014 at 22:13 UTC | |
by 2teez (Vicar) on Aug 26, 2014 at 21:52 UTC | |
| |
by Perl_Ally (Novice) on Aug 27, 2014 at 13:40 UTC | |
Re: Passing Along Arrays
by Laurent_R (Canon) on Aug 27, 2014 at 06:46 UTC | |
by Perl_Ally (Novice) on Aug 27, 2014 at 13:35 UTC |