develooper Front page | perl.perl6.language | Postings from May 2005

Re: (1,(2,3),4)[2]

Thread Previous | Thread Next
From:
Markus Laire
Date:
May 26, 2005 01:19
Subject:
Re: (1,(2,3),4)[2]
Message ID:
429585FB.1070504@laire.info
Rod Adams wrote:
> Austin Hastings wrote:
>> --- Rod Adams <rod@rodadams.net> wrote:
>>> TSa (Thomas SandlaƟ) wrote:
>>>
>>>> @m = [[1,2],[3,4]]
>>>
>>> @m[0;1] is a multidim deref, referencing the 4.
>>
>> Referencing the 2, I hope?
>>
> Doh!
> 
> Yes, the 2.

Really?

@m here has _single_ array-ref so
@m[0] returns that single array-ref - [[1,2],[3,4]]
@m[0;1] then returns array-ref [3,4]
@m[0;0] would return [1,2]
@m[0;0;1] would return 2

Double-checking with pugs: (multi-dim with ; doesn't work yet)

     pugs> my @m = [[1,2],[3,4]]
     ({ref:<Array>})
     pugs> @m[0]
     ({ref:<Array>}, {ref:<Array>})
     pugs> @m[0][1]
     (3, 4)
     pugs> @m[0][0]
     (1, 2)
     pugs> @m[0][0][1]
     2

@m = [[1,2],[3,4]] IS NOT same as @m = ([1,2],[3,4])

     pugs> my @m = ([1,2],[3,4])
     ({ref:<Array>}, {ref:<Array>})
     pugs> @m[0]
     (1, 2)
     pugs> @m[0][1]
     2

--
Markus Laire

Thread Previous | Thread Next


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