in reply to Re^2: How to check if a scalar value is numeric or string?
in thread How to check if a scalar value is numeric or string?
But watch out for side effects.
my $x = 1; my $y = '1'; print "x is a ", (($x ^ $x)?"string":"number"), "\n"; print "y is a ", (($y ^ $y)?"string":"number"), "\n"; print "\$x = $x\n"; print "\$y = $y\n"; print "x is a ", (($x ^ $x)?"string":"number"), "\n"; print "y is a ", (($y ^ $y)?"string":"number"), "\n"; my $z = $x + $y; print "\$z = $z\n"; print "x is a ", (($x ^ $x)?"string":"number"), "\n"; print "y is a ", (($y ^ $y)?"string":"number"), "\n";
gives
x is a number y is a string $x = 1 $y = 1 x is a number y is a string $z = 2 x is a number y is a number
It might be better to revise your program so that it doesn't depend on such a subtle distinction.
|
---|