Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Passing arguments from a Perl script to another

by techie411 (Acolyte)
on Oct 04, 2010 at 18:34 UTC ( #863406=perlquestion: print w/ replies, xml ) Need Help??
techie411 has asked for the wisdom of the Perl Monks concerning the following question:

I'm executing one Perl script to another....and I'm trying to pass arguments automatically from one to the other. This doesn't work:
#!/usr/bin/perl use strict; use warnings; my $otherScript = '/usr/local/bin/script'; system ("$otherScript test"); $ARGV[0] = "First"; print $ARGV[0];
I only see it filled when I exit the script. What can I do to pass the arguments? Thanks!

Comment on Passing arguments from a Perl script to another
Download Code
Re: Passing arguments from a Perl script to another
by toolic (Chancellor) on Oct 04, 2010 at 18:49 UTC
    To pass all args to your called script, try this:
    system ("$otherScript @ARGV test");
      But keep in mind that this way of calling also involves a shell which may interfere with possible shell-special characters in @ARGV.

      Probably a safer way would be this:

      system($^X, $otherscript, @ARGV, "test");
      which bypasses a shell ($^X is the path to the current Perl-interpreter).
Re: Passing arguments from a Perl script to another
by GrandFather (Cardinal) on Oct 04, 2010 at 20:36 UTC

    If you have control over the second script make it what "Effective Perl Programming (second edition)" calls a modulino - a module that can be run as a script or used as a module. Consider:

    use strict; use warnings; package Demo; sub run { print "Hello world\n"; } run (@ARGV) if ! caller (); 1;

    which executes the run sub when run from the command line, or can be used in another script where you can call Demo::run () to have the same effect as running it from the command line, but with the advantage that it is now trivial to pass and return data.

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://863406]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-12-21 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (107 votes), past polls