As the previous replier stated you can't. You pass a list of -values- (by value) to your second script.
You CAN pass an array by values (unroll it), pass the values, then roll it back up as an array. i.e.:
#!/usr/bin/perl
# test1.pl
use strict;
use warnings;
my $array = ( 1, 2, 3, 4);
open my $FH, '| ./test2.pl';
print $FH @{$array};
close $FH;
#!/usr/bin/perl
# test2.pl
use strict;
use warnings;
while (my $var = <>){
print $var;
}
However, it is safer to use exec or system then using the two argument open method for opening a file handle.
i.e.:
#!/usr/bin/perl
# test1.pl
use strict;
use warnings;
my $array = ( 1, 2, 3, 4);
my $program = 'test2.pl';
exec { $program } @{$array};
#!/usr/bin/perl
# test2.pl
use strict;
use warnings;
print "$_ " foreach @ARGV;
an aside:
`exec` can be written:
exec { $program } @{$array};
exec $program, @{$array};
exec { './test2.pl' } @{$array};
exec './test2.pl', @{$array};
exec './test2.pl', 1, 2, 3, 4;
That being said, you may want to investigate modules as this is probably more along the lines of what you are looking for. (I could be way off about the modules, but in general, every time I've wanted to call an external -Perl- script, I've been able to solve my problem more effectively by writing a module that I then import; as you haven't provided any details about the context in which you are attempting to call this external script, I could be wrong.)