in reply to How can I test for the representation of an integer?
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
|
---|