Link to home
Start Free TrialLog in
Avatar of macleod999
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.
Avatar of ozo
ozo
Flag of United States of America image

print "@$_\n" for @array;
Avatar of PC_User321
PC_User321

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]};
# variation of prvious suggestion:
grep((print "@$_\n"),@array);
ASKER CERTIFIED SOLUTION
Avatar of Sapa
Sapa

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of macleod999

ASKER

Thanks everyone; yeah, there were a few things I was doing wrong...