Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Testing legacy CGI scripts using the "main() unless caller()" techniqueby choroba (Cardinal) |
on Jul 20, 2022 at 21:48 UTC ( [id://11145613]=note: print w/replies, xml ) | Need Help?? |
You never know that the expression in unless caller() is the last evaluated one. There can be many more expressions scattered among the sub definitions, setting lexical variables or whatever. Putting a true value at the very end of the file means it will always behave correctly, regardless of the changes in the unless versus if ! line, or anywhere else. BTW, You might notice my pm files usually end with the following line:
It's a true value (I don't use 0.pm), but more importantly, there's no semicolon after it. If you try adding another sub or anything else below it, you'll get a syntax error. (I do the same thing with return). Your taste might be different.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|