script.pl that defines package Foo. now, for complex legacy reasons, your stuck with this and need to call script.pl both from the command-line as well asrequire "script.pl";
Foo->import;
how do you create a chunk of code that only executes from the command-line and not when script.pl is loaded or imported?
I might be missing something obvious, but the only thing I could come up with was requiring some random command-line argument and checking @ARGV. apparently that's not an option.
just off the top of my head (Score:1)
Re:just off the top of my head (Score:2)
Re:just off the top of my head (Score:1)
Re:just off the top of my head (Score:1)
perhaps... (Score:2)
Re:perhaps... (Score:2)
Will caller() do what you need? (Score:1)
#!
#
# script.pl
#
if (scalar caller)
{
print "Called via a sub, eval, or require.\n";
}
else
{
print "Called directly.\n";
}
print "Within script.pl\n";
You could get fancier with caller() if you need to, but I think this will do the trick.
There's more info in this recent journal entry by brian [perl.org].
--Bill
Re:Will caller() do what you need? (Score:1)
Yep; that's exactly the trick in Pod::ToDemo [cpan.org].