in reply to calling a perl script within a perl script
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:
orsystem("...") && die "Can't run ...: $!\n";
orsystem("...") == 0 || die "Can't run '...' [$?]: $!\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.open("... |") || die "Can't run ...: $1\n";
`` 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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: calling a perl script within a perl script
by sauoq (Abbot) on Nov 27, 2005 at 12:55 UTC |