Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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
[kcott]: marioroy, not much to go on. Searching "slow logging" (by me) produces no results; just "slow" gives a screenful. Perhaps, "Searching large files a block at a time" which had a performance aspect and you had some imput also.
[gnosti]: Hi, Looking for a module that can add HH:MM:SS durations like 1:40, 1:00:24.13 and 12.3? I see on CPAN more modules with absolute dates. TIA
[kcott]: s/imput/input/
[Corion]: DateTime::Duration ? Personally,I convert stuff to seconds using Time::Piece or Time::Local and then add the seconds and then use POSIX::strftime to print them as hours again
[marto]: good morning all, TCIF
[gnosti]: I'm reading from ffmpeg lengths of video clips in H:M:S and needing to add them and format them back to H:M:S for feeding back to ffmpeg
[marioroy]: kcott Thanks

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2017-08-18 08:53 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (297 votes). Check out past polls.