* On Wed, Jan 20 2010, rolfy wrote:
> The original intent was to stop having to go:
> print "Blah\n" if ($bTestMode);
> print "Blah blah\n" if ($bDebugMode);
> etc.
>
> Now I'd just go
> $dbg->debug("Blah blah");
> $dbg->test("Blah");
The reason people write the first form is because the print call is
completely removed from the optree (at compile-time) when one of the
constants is 0. (Actually, it needs to be a constant, not a variable.)
When you write the second form, you have to do a method lookup at
runtime, even if you are not in debugging mode, which is infinitely
slower than the "nothing" that the first method requires at runtime.
FWIW, I never care about speed this much, and always use a log object
(and never a *global* log object) for logging. But there is a reason
why people write "say 'foo' if DEBUG" other than laziness.
Regards,
Jonathan Rockway
--
print just => another => perl => hacker => if $,=$"