Uh, sorry. Seems like I've been barking up the wrong tree all the time.

But! since you wrote

My script has the global $verbosity which is set by command line args.

I ask - does this value change ever after? Because if not, you can make that a static via

BEGIN { my $verbosity = shift; # or Getopts::Std, whatever... eval "sub verbose () { $verbosity }"; }

of course only after examining under severe scrutiny what $verbosity holds (untaint, perlsec).

Since the BEGIN block is a separate compile & run, the sub is defined and a constant sub after that, and its value can be used for optimizations. If the values you compare $verbose with are plain numbers as the 1 in

print "Holy Crap = $holy_crap\n" if $verbose >= 1;

then optimization should work, because then you have constant vs. constant comparisons. Let's see...

qwurx [shmem] ~ > perl -MO=Deparse,-x,-p - 1 BEGIN { my $verbose; 1 while ($verbose = shift) !~ /^\d$/; # get rid of -MO=Dep... eval "sub verbose () { $verbose }"; } print "Holy Crap = $holy_crap\n" if verbose >= 1; __END__ sub BEGIN { my($verbose); '???' while (not (($verbose = shift(@ARGV)) =~ /^\d$/)); eval("sub verbose () { $verbose }"); } print("Holy Crap = $holy_crap\n"); __DATA__ - syntax OK qwurx [shmem] ~ > perl -MO=Deparse,-x,-p - 0 BEGIN { my $verbose; 1 while ($verbose = shift) !~ /^\d$/; # get rid of -MO=Dep... eval "sub verbose () { $verbose }"; } print "Holy Crap = $holy_crap\n" if verbose >= 1; __END__ sub BEGIN { my($verbose); '???' while (not (($verbose = shift(@ARGV)) =~ /^\d$/)); eval("sub verbose () { $verbose }"); } '???'; <----- hooray! gone :-) __DATA__ - syntax OK

bingo :-)

--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^7: 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.