Before you implement any of the above methods, there's a simple step I think you should take that may save you some trouble:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.