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}

In reply to Re^5: Macro in perl code? by shmem
in thread Macro in perl code? by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.