in reply to Re^4: Macro in perl code?
in thread Macro in perl code?
sub X() { 0 } print "$message1 \n" if( runtime cond);
Erm, no. The sub and the print statement being on the same line is an artifact of the code being a oneliner :-)
The point is that
sub X() { 0 }
is folded into a constant at compile time (more accurate after compiling - while optimizing), and the resulting constant is used by the optimizer to further reduce the optree throwing away code which, depending on that constant, is never reached.
So, it's not a (runtime cond). You get a mandatory warning if you redefine the constant defining sub X() { } at runtime, and you won't get back code that has been optimized away after compile.
I assumed that since the OP did preprocessing with m4 even before the perl compiler sees the code, the value for his $verbose doesn't change at runtime, but I may be mistaken. Conditional code that depends (or could depend) on runtime state can't be optimized that way, so there's a difference in writing
{ my $debug = 0; if ($debug) { warn "debug set\n"; } }
and
{ sub debug () { 0 } if (debug) { warn "debug set\n"; } }
Only in the latter case the if() block is optimized away, even if, in the former, there's no place in the scope in which the my $debug is declared, where its value would change.
qwurx [shmem] ~ > perl -MO=Deparse,-x,-p { my $debug = 0; if ($debug) { warn "debug set\n"; } } __END__ { (my $debug = 0); if ($debug) { warn("debug set\n"); } } __DATA__ (<Ctrl>D pressed) - syntax OK qwurx [shmem] ~ > perl -MO=Deparse,-x,-p { sub debug () { 0 } if (debug) { warn "debug set\n"; } } __END__ sub debug () { 0 } { '???'; } __DATA__ (<Ctrl>D pressed) - syntax OK
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Macro in perl code?
by Krambambuli (Curate) on Oct 17, 2007 at 09:21 UTC | |
|
Re^6: Macro in perl code?
by pileofrogs (Priest) on Oct 17, 2007 at 16:01 UTC | |
by shmem (Chancellor) on Oct 17, 2007 at 19:44 UTC | |
by ikegami (Patriarch) on Oct 17, 2007 at 19:53 UTC |