in reply to How to call other programs

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...

  • Comment on Re (tilly) 1: How to call other programs

Replies are listed 'Best First'.
Re: Re (tilly) 1: How to call other programs
by Jonathan (Curate) on Feb 01, 2001 at 21:41 UTC
    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.
      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.

        Thank you for the follow up.
        The main cause of the sharing warning (as far as I can see) is my own scripts because I'm using Apache::Registry which means that my scripts run via a handler sub (there are no warnings when run off-line).
        I think I'll have to make the sub routines anonymous to get round it.