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


in reply to detecting of scalar is string or numeric

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