Very near the top of each of your two scripts, put the following code:
use strict; if (! caller) { main(); exit 0; } sub main { # leave some room here. }
Now, when you run your scripts they will do nothing. Pull in things from the file-level into this new main sub you've created, until each script works exactly as it had worked before (it helps if you already have some regression tests).
Then, when doing the actual merge, put the code that selects either run mode before this new main (which now you have to call main_script1 and main_script2, only please use better names instead). Put it right there in the if statement, instead of the call to main.
The purpose of this whole exercise is to keep yourself from forgetting stray code that might have been hiding between subs, and if you hadn't been using strict, prevent global variables that had the same name from each script from interfereing with each other.
This is really modest advice; but it helps to force you to do cleanups on one front at a time, if they turn out necessary. Of course maybe your code is already squeaky clean and you don't need all this :)
In reply to Re: Combining two scripts with a command line switch?
by gaal
in thread Combining two scripts with a command line switch?
by Seventh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |