if ($x ^ $x) {print "string\n";}Seems to me that this will print "string" when and only when neither the NOK or IOK flag is set.
That being so, an alternative is to check whether the IOK or NOK flag is set - for which a module probably exists, or you could do it via XS or Inline::C.
use strict;
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1,
;
use Inline C => <<'END_C';
int foo(SV * in) {
if(SvIOK(in) || SvNOK(in)) return 1;
return 0;
}
END_C
my $num = 42;
my $str = "42";
my $ref = \$num;
my $nv = 42.42;
my $dual = "42"; # POK flag set.
if($dual > 0){} # IOK flag also set
print foo($num), " ", xor_check($num), "\n";
print foo($str), " ", xor_check($str), "\n";
print foo($ref), " ", xor_check($ref), "\n";
print foo($nv) , " ", xor_check($nv) , "\n";
print foo($dual), " ", xor_check($dual), "\n";
sub xor_check {
return 0 if($_[0] ^ $_[0]);
return 1;
}
__END__
Outputs (perl-5.24.0):
1 1
0 0
0 0
1 1
1 1
Now, you might be able to find a variable for which foo() and xor_check() return different values.
I'm certainly interested to know if someone can provide such an example.
Cheers,
Rob
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.