Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Find out, if "use warnings(all)" and "use strict(all)" are used

by Krambambuli (Curate)
on Apr 23, 2007 at 14:39 UTC ( [id://611529]=note: print w/replies, xml ) Need Help??


in reply to Find out, if "use warnings(all)" and "use strict(all)" are used

It's important I believe to cut a very clear line between what happens at compile time and what happens at runtime. Once those very distinctive steps are put apart and understood, it might be that your question changes.

Playing a bit with BEGIN{} might help in getting things apart;
use strict; my $all; use warnings 'all'; BEGIN { $all = unpack( 'b*', ${^WARNING_BITS} ); } print "ALL : $all\n"; my $none; no warnings 'all'; BEGIN { $none = unpack( 'b*', ${^WARNING_BITS} ); } print "NONE: $none\n"; my $void; use warnings 'void'; BEGIN { $void = unpack( 'b*', ${^WARNING_BITS} ); } print "VOID: $void\n";
This will display at runtime the values in use at compile time _at that specific point in the program_.

Note that to unpack ${^WARNING_BITS} - a 96 bits value - your bintodec sub won't work.

You might be interested in having a look on the warnings.pm source code - it's not really scary and definitely worth a look - and maybe check the 'Pragmatic modules' in perlmodlib.

Hope that helps.
  • Comment on Re: Find out, if "use warnings(all)" and "use strict(all)" are used
  • Download Code

Replies are listed 'Best First'.
Re^2: Find out, if "use warnings(all)" and "use strict(all)" are used
by Tobiwan (Beadle) on Apr 23, 2007 at 20:49 UTC
    Thanks, that was a good hint. I tried to read the warning and strict bits from other packages, so I've to find a way to do it without explicit BEGIN blocks. The following thing works, but why ?!?
    package Aa; use warnings; #no warnings 'void'; use strict; #no strict 'refs'; package Bb; #>> when you uncomment this, it wont work!! #use strict; #use warnings; #<< my $strict = eval('package Aa;my $h;BEGIN { $h = ${^H} };return $h;'); printf "use strict " . ($strict == 1794 ? 'yes' : 'no') . "\n"; my $warn = eval('package Aa;my $w;BEGIN { $w = ${^WARNING_BITS} };retu +rn $w;'); printf "use warnings " . (unpack('b*', warnings::bits('all')) == unpac +k('b*', $warn) ? 'yes' : 'no') . "\n";
    This prints:
    use strict = yes
    use warnings = yes
    
    till you use all-warnings ans all-stricts. Conclusion: it works fine and do what I want.

    And by the way: in last few weeks I've see a lot of little perl wonders like this. I think, there must be a perl-good. Now I'm a believer :D

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://611529]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found