Up until 5.24 where it was deprecated, one could safely use
$x ^ $x
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)
% 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
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?

In reply to detecting of scalar is string or numeric by vkhera

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.