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.
|
---|
In Section
Seekers of Perl Wisdom