develooper Front page | perl.perl5.porters | Postings from January 2011

Re: Using smart matching to find whether an array contains a string

Thread Previous | Thread Next
From:
John Peacock
Date:
January 26, 2011 09:14
Subject:
Re: Using smart matching to find whether an array contains a string
Message ID:
4D405682.6000900@havurah-software.org
On 01/26/2011 12:06 PM, Brad Baxter wrote:
> Perl *is* storing '1 x' as a number.  Very interesting.

Not exactly:

$ perl -MDevel::Peek -E '$b = "1 x"; say Dump($b); 0 + $b; say Dump($b); 
say $b."yz"'
SV = PV(0x14aceb68) at 0x14aee1d0
   REFCNT = 1
   FLAGS = (POK,pPOK)
   PV = 0x14ae80f0 "1 x"\0
   CUR = 3
   LEN = 8

SV = PVNV(0x14ad0290) at 0x14aee1d0
   REFCNT = 1
   FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK)
   IV = 1
   NV = 1
   PV = 0x14ae80f0 "1 x"\0
   CUR = 3
   LEN = 8

1 xyz


The first type we dump $b is as a pure "string" where the second time, 
$b is now both a string and a number (actually an integer and a floating 
point).  As you can see, if you perform an explicit string operation 
line catenate, the PV value is used, not the IV or NV...

John

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About