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:
Reini Urban
Date:
January 26, 2011 11:09
Subject:
Re: Using smart matching to find whether an array contains a string
Message ID:
AANLkTikr7d-ERJ3hogWKseJgezMNoiaDdHiON8LRj2Q3@mail.gmail.com
2011/1/26 John Peacock <john.peacock@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...

You probably miss -w


$ perl -we'print 0 + "1 x"'
Argument "1 x" isn't numeric in addition (+) at -e line 1.
1

$ perl -e'print 0 + "1 x"'
1

-- 
Reini Urban
http://phpwiki.org/           http://murbreak.at/

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