Re: How do I tell if strict, taint, etc are on?
by zer (Deacon) on Mar 16, 2006 at 20:17 UTC
|
the variables following state if they are on:
${^TAINT}
$^W # Warnings
for those who are searching and find this, take a look at Perl Special Variables Quick Reference | [reply] [d/l] |
|
use warnings;
print($^W, "\n"); # 0 XXX
| [reply] [d/l] [select] |
|
Thanks; that helps. I feel foolish for missing that on the perlvar page.
| [reply] |
Re: How do I tell if strict, taint, etc are on?
by Fletch (Bishop) on Mar 16, 2006 at 19:47 UTC
|
You might could weasel it out of one of the special variables ($^H looks remotely promising; see perlvar), but then the question that springs to mind is: Why? Tainting I could see possibly (you want to not run unless it's enabled), but a use for runtime checking of strict-ness eludes me.
| [reply] [d/l] |
|
Yeah, I see $^H, thanks, but since the docs say explicitly "WARNING: This variable is strictly for internal use only", it doesn't sound exactly like a supported API. :)
As to why, well, I'm working on a diagnostic/debugging page
for some mod_perl web stuff, that shows me the environment,
database handles, process status, and so on. As part of
that, I wanted it to report as much as it could about
the state of the running perl environment - including
the various pragmas and what-not.
| [reply] |
|
Ahh. OK I can see that. :)
A problem that comes to mind right off is that strict is lexically scoped so you're probably not going to be able to tell from outside a given scope if it's on or off inside, at least as far as I can think of. You might be able to do some deep magic with one of the B modules, but I wouldn't count on it. If no one else here comes up with anything you might run this by p5p and see if anyone there can offer pointers.
| [reply] |
Re: How do I tell if strict, taint, etc are on?
by ikegami (Patriarch) on Mar 16, 2006 at 22:18 UTC
|
You can check for taint checking using $^T (documented in perlvar).
There's no such thing as strict being on or off. There are three kinds of strict checks which are independant. You can check their status by causing a violation in an eval:
my $strict_refs = not eval { no warnings; ${'var'}; 1 };
my $strict_subs = not eval 'no warnings; ThisDoesNotExist; 1';
my $strict_vars = not eval 'no warnings; $ThisDoesNotExist; 1';
Similar to strict checks, there's no such thing as warnings being on or off. There are many kinds of warning checks which are independant. $^W will tell you if -w on the command line (or equivalent), but each and all individual warnings can be enabled and disabled using warnings without affecting $^W. You can check if a particular warning is enabled using warnings::enabled().
| [reply] [d/l] [select] |
Re: How do I tell if strict, taint, etc are on?
by linux454 (Pilgrim) on Mar 17, 2006 at 03:10 UTC
|
As for checking if use strict and use warnings has been used, try:
print "strict module loaded... ",
exists($INC{'strict.pm'}) ? "yes" : "no",
"\n";
print "warnings module loaded... ",
exists($INC{'warnings.pm'}) ? "yes" : "no",
"\n";
Others have addressed testing for Taint.
Update: fixed typo noticed by been42 | [reply] [d/l] |
|
print "strict module loaded... ",
exists($INC{'strict.pm'}) ? "yes" : "no",
"\n";
print "warnings module loaded... ",
exists($INC{'warnings.pm'}) ? "yes" : "no",
"\n";
| [reply] [d/l] |
|
Thanks for catching that.
| [reply] |
Re: How do I tell if strict, taint, etc are on?
by DrWhy (Chaplain) on Mar 16, 2006 at 20:39 UTC
|
For strictness, you could look to see if $strict::VERSION is defined. This will only tell you whether strict has been used at some point in the code. It won't tell you whether any strictness is actually in effect at the point in the code you do the checking. For more specifics, I don't see anything better than interrogating $^H.
--DrWhy
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
| [reply] |