Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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!

Replies are listed 'Best First'.
Re: Passing arguments from a Perl script to another
by GrandFather (Sage) 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
Re: Passing arguments from a Perl script to another
by toolic (Bishop) 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).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://863406]
Approved by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2018-05-22 14:07 GMT
Find Nodes?
    Voting Booth?