rvosa has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I'll be darned, you can preprocess scripts before execution. Anyone ever do that??? I mean, not just to check it out, like I just did, but for real?

As I was thinking this through, I figured I might use a preprocessor to append my standard pod footer for my modules, i.e.:
cpp -o Module_with_pod_footer.pm Module_without_footer.pm
With a #include <footer.pod> directive in Module_without_footer.pm. But preprocessing before execution, I suppose that's more a perl4 kind of thing? I.e. before 'use' and other modularity?

I'd like to hear any sensible -P usage examples in perl5.

Replies are listed 'Best First'.
Re: perl -P myscript.pl
by polettix (Vicar) on Sep 26, 2005 at 15:05 UTC
    perlrun will clarify this issue, I only want to quote this:
    NOTE: Use of -P is strongly discouraged because of its inherent problems, including poor portability.

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re: perl -P myscript.pl
by Anonymous Monk on Sep 26, 2005 at 15:29 UTC
    It allows for quickly outcommenting large blocks of code. Using if (0) { ... } still compiles the enclosed block of code, and hence requires the code to compile, while =pod/=cut can be interfered if you try to outcomment a piece of code that contains POD.

    Uncommenting large sections with #if 0/#endif is the only usage I've done with -P. And then only while developing.