In article <fV45K0OBJxbE-pn2-qsKzC8oNCHJ7@localhost>,
Dave Saville <> wrote:
>On Sat, 7 Apr 2012 13:22:11 UTC, Willem <> wrote:
>
>> Dave Saville wrote:
>> ) On Sat, 7 Apr 2012 11:59:39 UTC, "Dave Saville" <>
>> ) wrote:
>> )
>> )<snip>
>> )
>> ) A bit of Googling turns up "do" which is yet another perl thing I
>> ) didn't know about
But although it works once I don't get
>> control ) back if the invoked script does not fail.
>>
>> The script you called probably has an 'exit' in there somewhere,
>> which causes your master script to exit.
>
>You are correct - I had just figured it out. Bother as I need multiple
>return values and "exit value" was the easy way and as it's a "main"
>script it won't let me use "return value"
Well, it's possible to get halfway there by wrapping the top-level
code (the stuff outside any sub bodies) in
sub init {
}
Then you can do a "return". But that's only halfway, ...
>So a complete restructure to exit at the end of the program by
>assigning the return code required to another variable as the last
>statement
.... because main programs don't work the way subs work: as "man
perlrun" says as of Perl 5.14:
If the program runs off the end without hitting an exit() or die()
operator, an implicit exit(0) is provided to indicate successful
completion.
Unless you're running these scripts hundreds of times per second, or
the machine is really old and slow, I'd suck it up and just invoke
them as regular programs. Except in those cases, any inefficiency
would be insignificant. "Micro-optimization leads to micro-results".
Or follow Peter J. Holzer's advice in the other direct reply to you
and put the guts into real libraries.
Or, if you still want the current structure, then (untested) in each
of the standalone scripts, head each with
package SomethingUniqueToThisFile;
to try to reduce the global namespace pollution, and invoke them as
(untested)
eval {
local @ARGV = (...);
do "the_script";
};
and also check its exit status, $@, and $!, as mentioned in the do doc
in perlfunc.
But each script can still pollute the global namespace. If one of
them sets $|, say, or some other special variable, your caller and
everything it calls afterwards will see it.
--
Tim McDaniel,