Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

system calls question

by Plato (Friar)
on Oct 08, 2004 at 04:57 UTC ( [id://397573]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Plato has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I am working on some old scripts, they're using a master perl script to call a load of other perl scripts, using system calls. For example:
print"script1.pl\n"; system("script1.pl"); print"script2.pl\n"; system("script2.pl"); print"script3.pl\n"; system("script3.pl"); etc...
In total about 20 scripts are called. Is it good practice to use system calls this way? What other methods are there for calling a load of scripts?

Thanks in advance,
Plato.

Replies are listed 'Best First'.
Re: system calls question
by gellyfish (Monsignor) on Oct 08, 2004 at 05:04 UTC

    If you are purely running perl programs with no arguments then you might want to consider using do [filename] which won't fork a new perl interpreter.

    /J\

Re: system calls question
by Jasper (Chaplain) on Oct 08, 2004 at 05:17 UTC
    cron?

    edit: wow, losing XP hand over fist with that.. But seriously, what's wrong with shell, or a batch file, or whatever? Isn't this exactly the sort of thing they'll do better than perl?
Re: system calls question
by Mutant (Priest) on Oct 08, 2004 at 07:15 UTC
    A lot of it depends on what you're doing with the scripts. In most cases, forking isn't really necessary, so as someone suggested:

    do 'script1.pl'

    If the master script is some sort of daemon (ie. it doesn't exit after being called), then forking is probably a good idea, since the memory will be freed after the script has executed.

    Unless these are something other than very basic system admin type scripts, you may want to consider re-coding the scripts as modules, and call them as a function.
Re: system calls question
by Grygonos (Chaplain) on Oct 08, 2004 at 08:57 UTC

    I'm really going to agree that it's just as efficient to run these via cron/batch/shell. If there is a specific purpose to running them from a perl script I would suggest the do 'x.pl' or forking (depending on your needs) methods described above.

Re: system calls question
by revdiablo (Prior) on Oct 08, 2004 at 13:51 UTC
    What other methods are there for calling a load of scripts?

    You could convert the scripts into modules that follow some specific API, then load each module and start it doing its work. For example, you could have a run function in each one that starts it off.

    Then voila, you have a basic plugin system. Make a certain directory to put the plugins, have your main script glob the directory and run each one. Next time you need to create a new "script", it's as easy as creating a module and saving it to the right place.

Re: system calls question
by hostyle (Scribe) on Oct 09, 2004 at 08:57 UTC
    foreach ("script1.pl", "script2.pl", "script3.pl") { print "$_ \n"; require; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://397573]
Approved by Arunbear
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.