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.)


In reply to Re: How to pass array as a reference from one perl file to other by PyrexKidd
in thread How to pass array as a reference from one perl file to other by romy_mathew

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.