in reply to Re^6: Macro in perl code?
in thread Macro in perl code?
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}
|
|---|