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

Re: $array[ 'Infinity' ]

by moritz (Cardinal)
on Dec 16, 2007 at 23:17 UTC ( #657339=note: print w/ replies, xml ) Need Help??


in reply to $array[ 'Infinity' ]

It prints only 5\n\n for me (with perl 5.8.8).

The $a['Infinity'] part is not surprising, because the string is coerced into an integer, which is 0.

I was quite surprised though that -Infinity is evaluated as -inf (and $a[-inf] is undef; no surprises here). A quick grep through the pod files in my perl distribution show that Infinity was introduced in perl561delta as a synonym for inf.

It's a bit weird that it dies under strict, IMHO.


Comment on Re: $array[ 'Infinity' ]
Select or Download Code
Re^2: $array[ 'Infinity' ]
by rgiskard (Hermit) on Dec 17, 2007 at 16:34 UTC
    If you really want a strict version:
    use strict; my @a = (5 .. 10); print $a['Infinity'], "\n", $a['-Infinity'], "\n"; print $a['Infinity'], "\n", $a['-Infinity'], "\n"; print 0+"Infinity" . "\n"; print 0+"-Infinity" . "\n";
    You still get:
    10
    5
    10
    5
    inf
    -inf
    
    The version:
    perl -v
    This is perl, v5.8.8 built for cygwin-thread-multi-64int...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-07-03 21:12 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 (56 votes), past polls