vkhera has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: detecting of scalar is string or numeric
by Corion (Patriarch) on Feb 08, 2017 at 13:56 UTC | |
|
Re: detecting of scalar is string or numeric
by haukex (Archbishop) on Feb 08, 2017 at 13:58 UTC | |
|
Re: detecting of scalar is string or numeric
by syphilis (Archbishop) on Feb 08, 2017 at 23:36 UTC | |
|
Re: detecting of scalar is string or numeric
by clueless newbie (Curate) on Feb 09, 2017 at 16:03 UTC | |
|
Re: detecting of scalar is string or numeric (SvTYPE)
by Anonymous Monk on Feb 08, 2017 at 23:34 UTC | |
by ikegami (Patriarch) on Aug 10, 2018 at 07:19 UTC |