in reply to do script2.pl with parms

Using do to call one script from inside another is considered not very elegant. Anyway.

#!/usr/bin/perl print "We're in script1 now\n"; @ARGV = ("super", "duper"); do('script2'); print "Back in script1\n";
In script2.pl then:
#!/usr/bin/perl print "\tNow we're in script2\n"; my ($arg1, $arg2) = @ARGV; print "\t- arg1: $arg1\n"; print "\t- arg2: $arg2\n"; print "\tscript2 ends\n";

So, one way to do it is to use @ARGV, the array that contains the list of "command line" arguments.

Replies are listed 'Best First'.
Re^2: do script2.pl with parms
by afoken (Chancellor) on Nov 12, 2010 at 13:44 UTC

    Add a (scope-limiting) block and local to that and @ARGV won't be damaged in script 1:

    # in script 1 { local @ARGV=(...); do('script2'); }

    But this is just an awful kludge.

    tel2, move (most of) the code of script 2 into a module. use that module in script 2 to get the existing behaviour. use that module also in script 1 to get the functions you need.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      A sometimes used technique is to use caller to distinguish between command line invocation as a script and use as a module:

      package DualUseScript; ... return 1 if caller; # script "main" code
      True laziness is hard work