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:
orunless ( defined caller ) { #code here }
sub do_me or the block after unless won't be executed when used or required, but will be executed from the command line.sub do_me { #code to run here } do_me unless defined caller;
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: testing in perl: main and caller
by chromatic (Archbishop) on Sep 05, 2005 at 02:37 UTC | |
by water (Deacon) on Sep 05, 2005 at 02:48 UTC | |
by chromatic (Archbishop) on Sep 05, 2005 at 06:14 UTC |
In Section
Seekers of Perl Wisdom