in reply to perl compiler optimizer curiosity

> 4. is there a better way to accomplish the goal of simple on/off for debugging one's code?

unfortunately there is no macro mechanism° in pure Perl.

If you want code to be folded away at compile-time, you have to put it inside an if(CONSTANT-VALUE) block.

Athanasius already showed you a way to do it.

Tho if you want nicer syntax, you can define a (kind of) macro with Keyword::Simple which only expands the debug-code if a condition is met.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

update

°) Lisp like that is

Replies are listed 'Best First'.
Re^2: perl compiler optimizer curiosity
by cavac (Prior) on Mar 15, 2022 at 11:11 UTC

    unfortunately there is no macro mechanism in pure Perl.

    Technically, there is. Although using source code filters is not a good idea, it's basically a smarter version of C makros.

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
      Sorry, if I say "macro" I mean real ones like in Lisp.

      Preprocessor macros like in C are sh*t in comparison.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        if I say "macro" I mean real ones like in Lisp. Preprocessor macros like in C are sh*t in comparison.

        I never used Lisp, but I know C. Can you show some examples?

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)