Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: $array[ 'Infinity' ]

by ikegami (Pope)
on Dec 16, 2007 at 23:19 UTC ( #657340=note: print w/ replies, xml ) Need Help??


in reply to $array[ 'Infinity' ]

-bareword is the same as "-bareword".

>perl -e "use Devel::Peek; $x="-bareword"; Dump($x); $x=-bareword; Dum +p($x)" SV = PV(0x226150) at 0x226000 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1835404 "-bareword"\0 CUR = 9 LEN = 12 SV = PV(0x226150) at 0x226000 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1835404 "-bareword"\0 CUR = 9 LEN = 12

There's nothing special about -Infinity.

>perl -e "use Devel::Peek; $x="-Infinity"; Dump($x); $x=-Infinity; Dum +p($x)" SV = PV(0x226150) at 0x226000 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1835404 "-Infinity"\0 CUR = 9 LEN = 12 SV = PV(0x226150) at 0x226000 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x1835404 "-Infinity"\0 CUR = 9 LEN = 12

A string that doesn't look like a number is the same as 0 in a numerical context (although it will give a warning if warnings enabled).

The index expression of an array is evaluated in a numerical context.

So they both print 5.

>perl -e"@a = (5 .. 10); print qq{$a['Infinity']\n$a[-Infinity]\n};" 5 5

Update: There appears to be a bug. 'Infinity' and -Infinity don't trigger the warning.


Comment on Re: $array[ 'Infinity' ]
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://657340]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-10-20 22:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (92 votes), past polls