to determine if the value of $x is a string or a numeric value. However, now, if your string contains high code points (like emoji characters) perl issues a deprecation warning (see the last line in this snippet)$x ^ $x
Since it still works, for now I'm just turning off that warning, but I need to find a replacement test. The Scalar::Util::looks_like_number() function doesn't do the same thing in that it considers the string form of "42" not to be a string in my test above. The purpose of this is to conditionally do utf8 encoding of a string for use with XMLRPC. The XMLRPC libraries need to detect if the variable holds a number or a string and generate the XML accordingly. I do not want to stringify numbers where I do not need to. I have not been able to find a replacement to this test searching this site and others. What should I do?% perl -Mutf8 -e '$x = 42; if ($x ^ $x) {print "string\n";}' % perl -Mutf8 -e '$x = 42.24; if ($x ^ $x) {print "string\n";}' % perl -Mutf8 -e '$x = "42"; if ($x ^ $x) {print "string\n";}' string % perl -Mutf8 -e '$x = "00042"; if ($x ^ $x) {print "string\n";}' string % perl -Mutf8 -e '$x = "42\N{BLACK TELEPHONE}"; if ($x ^ $x) {print "s +tring\n";}' Use of strings with code points over 0xFF as arguments to bitwise xor +(^) operator is deprecated at -e line 1. string % perl -v This is perl 5, version 24, subversion 1 (v5.24.1) built for amd64-fre +ebsd-thread-multi
In reply to detecting of scalar is string or numeric by vkhera
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |