Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 pondering the Monastery: (12)
As of 2015-07-01 21:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (22 votes), past polls