#!/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.:
an aside:#!/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;
`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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |