http://www.perlmonks.org?node_id=294867


in reply to Is this fundamentally different than my original try?
in thread use bytes without breaking perl 5.005 or 5.004?

Yes, same result. Here is how I tested it:

> perl { use warnings; } print $x; <EOF> > perl BEGIN { if( {require warnings} ) { warnings->import(); } } print $x; <EOF> Use of uninitialized value in print at - line 3. > perl BEGIN { eval { require warnings; import warnings; } } print $x; <EOF> Use of uninitialized value in print at - line 3. >
First is the "control" case to show that 'use warnings' inside of a block doesn't have an effect outside of the block. Next is my method, and the warning generated shows that there is an effect (since I have warnings.pm in this version of Perl). Last is your method, which also works.

The 'hint' pragmas all work very much the same so this trick works for 'strict', 'warnings', 'bytes', etc.

                - tye