 Perl: the Markov chain saw 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

```>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.

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 browsing the Monastery: (4)
As of 2020-09-25 01:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
If at first I don’t succeed, I …

Results (136 votes). Check out past polls.

Notices?