in reply to Re^2: De-Reference an array
in thread De-Reference an array

To understand what was meant by "All you're passing are the stringified references", change your code like this:

#!/usr/bin/perl # program.pl use warnings; use strict; my @array1 =( 1..3 ); my @array2 = ( 4..6 ); my $ref_array1 = \@array1; my $ref_array2 = \@array2; system("./print.pl",$ref_array1,$ref_array2);

...and the print.pl:

#!/usr/bin/perl use strict; use warnings; my ( $ref_string1 ,$ref_string2 ) = @ARGV; print "$ref_string1, $ref_string2\n";

...and run it.

You can use 'Storable' to save your data serialized into a file, and then have the print program lift it back up:

#!/usr/bin/perl use warnings; use strict; use Storable; my @array1 = ( 1..3 ); my @array2 = ( 4..6 ); my $store_file = './data.store'; # encapsulte the two arrays into a single array ref # for storage. We'll extract in print.pl store( [ \@array1, \@array2 ], $store_file ); # instead of passing the data as the parameters, pass the file name in +stead system( "./print.pl", $store_file );

...and the print....

#!/usr/bin/perl use strict; use warnings; use Storable; my $store_file = $ARGV[0]; # we have to extract the two original arrays from the # single array that we encapsulated them in my $aoa = retrieve( $store_file ); my ( $aref1 ,$aref2 ) = @{ $aoa }; print "@{ $aref1 }, @{ $aref2 }\n";

Hope this helps!

Steve

Replies are listed 'Best First'.
Re^4: De-Reference an array
by Ankit.11nov (Acolyte) on Oct 12, 2009 at 06:39 UTC
    Thanks Steve for the help on this.