do() is really more efficient than system().
There's no new process creation with do and it's a key avantage for your problem ( process creation is time/ram/cpu consuming ). Yours do'ed scripts share global vars with your main script ( this should be usefull also ).
Hope this helps :)
| [reply] |
Thanks Gloom, pretty much confirming what I suspected.
| [reply] |
I should note some gotchas. First of all if the scripts in
question call exit, your script exits as well. Secondly
if the scripts in question play with global variables, you
could have your namespace messed up with at all.
Having had the misery of maintaining Perl written as if it
was shell, I strongly recommend taking the functionality
in those scripts and moving it into modules, then rewriting
both the individual scripts and your new programs to load
the modules and call them.
Trust me, I have been there, done that, don't recommend the
scars... | [reply] |
Thanks for that Tilly. I've already got to review the called scripts to trap any 'Variable "$foo" will not stay shared' warnings (the current bane of my life), I'll add exit to the list.
| [reply] |
If I am not mistaken, $foo will not stayed shared is a sign
that they are using as globals the same thing that
you declared to be lexical. That can be fixed by
moving the functionality of how you do a call into its own
module that doesn't have any lexicals.
But have you trapped the case where they are using the same
global variables as each other?
You can fix that, sort of, by wrapping your do in an
eval that puts each invocation into a private package.
Of course if they use package also, you are out of
luck again on the global issue. Likewise if they
sometimes refer to variables as being explicitly in package
main. Not to mention the joys of global signal handlers.
Please trust me when I say I have the scars and don't
recommend that route long-term. Refactoring the code into
modules is not that hard, and once done you gain a lot of
flexibility.
| [reply] |
As far as I know do <file> is strictly equivalent to
scalar eval<file>
I may be wrong but do seems to be better (than system) in term of use of memory...
| [reply] [d/l] [select] |
I thought do was more efficient, well thats what my Camel tells me anyway :)
| [reply] |