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.)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.