Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: testing in perl: main and caller

by bmann (Priest)
on Sep 05, 2005 at 02:14 UTC ( #489107=note: print w/ replies, xml ) Need Help??

in reply to testing in perl: main and caller

I'm not sure if this is what chromatic suggested, but either one of these should do what you're looking for:

unless ( defined caller ) { #code here }
sub do_me { #code to run here } do_me unless defined caller;
sub do_me or the block after unless won't be executed when used or required, but will be executed from the command line.

From perldoc caller:

Returns the context of the current subroutine call. In scalar context, returns the caller's package name if there is a caller, that is, if we're in a subroutine or eval or require, and the undefined value otherwise.

Comment on Re: testing in perl: main and caller
Select or Download Code
Replies are listed 'Best First'.
Re^2: testing in perl: main and caller
by chromatic (Archbishop) on Sep 05, 2005 at 02:37 UTC

    That's basically what the book suggests. Thanks!

      what does the test code look like, then?
      isn't correct, clearly.


        The book has:

        ok( require( '' ), 'loaded file successfully' ) or exit;

        I think require_ok() would also work, though I'm not in a position to try it right now, nor do I remember if I wrote it as above for a specific reason.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://489107]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-11-28 19:48 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (744 votes), past polls