Hi sm@sh,

I don't know much about the internals, but from what I do know I'd guess it might be looking at the POK/IOK flags:

$ perl -MDevel::Peek -e 'Dump(1); Dump("1")'; SV = IV(0x21490e8) at 0x21490f8 REFCNT = 1 FLAGS = (IOK,READONLY,PROTECT,pIOK) IV = 1 SV = PV(0x2129fa0) at 0x2149168 REFCNT = 1 FLAGS = (POK,IsCOW,READONLY,PROTECT,pPOK) PV = 0x218fef0 "1"\0 CUR = 1 LEN = 10 COW_REFCNT = 0 $ perl -MDevel::Peek -e '$a=42; $a="Hello"; Dump($a)'; SV = PVIV(0x83d2e0) at 0x8321f0 REFCNT = 1 FLAGS = (POK,IsCOW,pPOK) IV = 42 PV = 0x834920 "Hello"\0 CUR = 5 LEN = 10 COW_REFCNT = 1

However, the much bigger question on my mind is why you need to know this? Perl "casts" between strings and numbers transparently, except for the case where a string can't be converted to a number, which you can determine beforehand with Scalar::Util's looks_like_number. Are you writing code that needs to peek behind the curtains more than that?

Regards,
-- Hauke D


In reply to Re: How can I test for the representation of an integer? by haukex
in thread How can I test for the representation of an integer? by sm@sh

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.