I got an really old perl system (approx 8-10 years old), but a big one (100+ pm files). Now for some reason need "remodernize" it - step-by-step.
One of first thing what i want get done is insert into every module my pragma:
use MySw::PerlDefs;
what will contain things like in Modern::Perl and/or as in this question: How to make "use My::defaults" with modern perl & utf8 defaults?
QST1: What is the recommended way?
adding use MySw::PerlDefs;
so will get
package MySw::SomePackage; use MySw::PerlDefs; #my new "pragma"
or add the PerlDefs enclosed in the BEGIN block after the package declaration? e.g.:
package MySw::SomePackage; BEGIN {use MySw::PerlDefs;} #my new "pragma" in the BEGIN block
Questions:
Ps: I understand than the BEGIN exectuted at compile time, but in the above context - it is not better than the "simple use"?
Wrapping the use in a BEGIN block is not going to work; the effect of lexical pragmas will not extend beyond the end of the block.
Compare:
$ perl -e'BEGIN{ use Modern::Perl; } $x=42; print "$x\n"'
42
$ perl -e'use Modern::Perl; $x=42; print "$x\n"'
Global symbol "$x" requires explicit package name at -e line 1.
Global symbol "$x" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With