in reply to Re: Template to create modules
in thread Template to create modules

Looking at the examples given surprise me one thing: just one of the samples gave me this "BEGIN" and "END" (the one provided through the perlmod).

I've read now one article about this thing called BEGIN and it says on one comment:

"You didn't mention that BEGIN blocks even run when syntax checking with perl -cw. That's always seemed worrying on a security basis to me - I'm checking the syntax of the program, not running it! What if the BEGIN block does system( "rm -rf ...")?"

So trust on code that has this feature is a bit dangerous when you want to just syntax check...

For the curiosity I've checked if the library that I'm using to learn perl use this feature and it doesn't! (see here).

Replies are listed 'Best First'.
Re^3: Template to create modules
by choroba (Cardinal) on Jun 15, 2016 at 07:56 UTC
    > I've checked if the library that I'm using to learn perl use this feature and it doesn't!

    Sure it does. You need to follow the use clauses, line #11 says

    use JSON;

    which in turn, on line #9, says

    BEGIN {

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,