I'm wondering if there's a way to determine what pragmas are active within a specific scope.
perlvar suggests %^H but it doesn't seem to do anything useful in the following one-liner:
$ perl -e 'use strict; use warnings; use utf8; use Data::Printer; p %^H'
{}
I ask since it took me quite a while to figure out that an implicit utf8 pragma loaded by Mojolicious::Lite was creating trouble that my Regexp::Grammars tests had failed to capture, and I hope there's a better way to troubleshoot such problems.
%^H is for making your own pragmas. strict, warnings and utf8 all set bits in $^H.
But changes to both $^H and %^H are restored at the end of the BEGIN block being executed. So you need to use caller to access their value at run-time.
$ perl -e'
use Data::Printer;
sub f {
CORE::say sprintf "%X", (caller(0))[8];
p %{ (caller(0))[10] // {} };
}
{
use strict;
use warnings;
use utf8;
f();
}
{
f();
}
'
8007E2
{}
0
{}
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