Is this really what you want to do?

Is the script you're calling big and unchangeable? If it's only a small one wouldn't it be better to include its code into your script?

If it's a big one, can you clone it and make a copy that's got this loop around its functionality?

If you're running an external command using backticks `` like that - firstly as sk pointed out you have put the filename outside the backticks, so it won't be provided as an argument to the script you're running, but I wouldn't recommend using backticks in the first place.

If you really must shell out to an external program you're better to use:

system("...") && die "Can't run ...: $!\n";
or
system("...") == 0 || die "Can't run '...' [$?]: $!\n"
or
open("... |") || die "Can't run ...: $1\n";
if you want the output from it - this way the operating system is going to report back to your script whether the program you shelled out to returned an error or a success.

`` is easy to use but generally sloppy in that it says something like "go away and try and run this, I don't really care if it works or not, but just give me back whatever came back from STDOUT (I don't care about STDERR either)" - which probably isn't what you want your program to do!

Update:

Thanks sauoq for pointing out the obvious mistake - NB system() unlike open() returns the output of the program that you ran modified by some rules (which sauoq has expanded below)

Sorry I rushed out my answer as I was racing out the door running late for a conference!


In reply to Re: calling a perl script within a perl script by serf
in thread calling a perl script within a perl script by sbp

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.