if you need the output from the second perl script you run...
$resp = `script2.pl \Q$var1\E \Q$var2\E`;
the \Q and \E escape any strange characters in var1 and var2 so they don't screw up the call (like & and ' etc), and script2.pl will see those values in the @ARGV array var1 in $ARGV[0] and var2 in $ARGV[1]... the exit value of script2.pl will be in $?

if script2.pl puts out a lot of info you may want something more like

open(CMD, "script2.pl \Q$var1\E \Q$var2\E") or die $!; while(<CMD>) { chomp; print ">>$_\n"; } close CMD;
that does essentially the same thing as the ``, except you get the output of script2.pl line by line in $_ in the while loop. (chomp removes the trailing \n from $_)

Finally there is system, which returns the exit code of the script, not the output, the output just goes normally to STDOUT

if(system("script2.pl \Q$var1\E \Q$var2\E")){ print "Error running script2.pl!\n"; }

                - Ant
                - Some of my best work - Fish Dinner


In reply to Re: Executing a perl script from a perl script??? by suaveant
in thread Executing a perl script from a perl script??? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.