Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
We have a monster script that ought to be refactored, but since that's not going to happen, I wanted to at least write some regression tests for how it currently works. One saving grace is that does a lot of its work in subroutines. Is there a way I can pull all these subroutine definitions into my test script without running

I can't use use or require or even do, because explicitly exits.

Of course I could copy the subs into another file, but I want my test script to run against the current live version.

Of course the subs ought to be placed in one or more modules in separate files, but take my word for it, this is not going to happen.

How does perl -c do what it does? Somehow it compiles the code without running it. How can I do the same thing?


Thanks for all these answers!

The key idea seems to be to slurp the file and then wrap the contents in some construct that cancels the run-time phase.

In fact, I've just thought of my own variation (untested):

my $prog_code; my $test_code; # slurp into $prod_code # slurp a test suite into $test_code eval "CHECK {$test_code} $prog_code";

In reply to SOLVED: How to load the subs without running the script by Narveson

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (4)
    As of 2018-10-17 20:03 GMT
    Find Nodes?
      Voting Booth?
      When I need money for a bigger acquisition, I usually ...

      Results (97 votes). Check out past polls.