develooper Front page | perl.perl6.language | Postings from January 2003

Re: More Array Behaviors

From:
John Williams
Date:
January 27, 2003 14:38
Subject:
Re: More Array Behaviors
Message ID:
Pine.LNX.4.33.0301271231400.26403-100000@sharkey.morinda.com
On Mon, 27 Jan 2003, Michael Lazzaro wrote:

> Some requests for verification, plus additional questions.  If anyone
> has any arguments/clarifications/questions on these, please discuss so
> I can document.
>
> 1) Edge cases in array indexing:
>
>      @a[ undef ]   # undef, or 1?
>      @a['foo']     # undef, or 1?

These should generate warnings, at least.

I don't know whether undef or 1 is more correct.

Perl5 chooses 1, but it's smart enough to distiguish between $a["1e0"]
(returns 2) and $a["1e"] (returns 1 and a non-numeric warning), so it's
definitely choosing to return $a[0] for non-numeric indexes.
(0+"1e" is 1, not 0)

> Is [undef] the same as [0] in Perl6?  Is there any index value you can
> give that will cause an exception?

What about @a[NaN]?  Just another warning probably.

~ John Williams





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About