macleod999
asked on
'require' file returns only address of array, not array contents
I have two perl files. I want the second one to include the code of the first. Example:
*perl1.pl*
@array = ([1, 2, 3],
[4, 5, 6]);
*perl2.pl*
require 'perl1.pl';
print @array;
When perl2.pl is executed, the print statement returns ARRAY(0x1abf0cc) instead of the values in the array. Is there any way to use arrays in this fashion? $scalars work as expected.
*perl1.pl*
@array = ([1, 2, 3],
[4, 5, 6]);
*perl2.pl*
require 'perl1.pl';
print @array;
When perl2.pl is executed, the print statement returns ARRAY(0x1abf0cc) instead of the values in the array. Is there any way to use arrays in this fashion? $scalars work as expected.
print "@$_\n" for @array;
The 'require' makes no difference.
Just print as you would have in perl1.pl.
For example
print "One value: $array[0][1]\n";
print "Second array: ";
print join ", ", @{$array[1]};
Just print as you would have in perl1.pl.
For example
print "One value: $array[0][1]\n";
print "Second array: ";
print join ", ", @{$array[1]};
# variation of prvious suggestion:
grep((print "@$_\n"),@array);
grep((print "@$_\n"),@array);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everyone; yeah, there were a few things I was doing wrong...