in reply to Re^2: Array/List Strangeness (why)
in thread Array/List Strangeness
BTW, if you want to avoid this particular bit of magic, you can rewrite your list slice as an array slice: [get_a_list()]->[7,0]. And, as quietly noted in the documentation, if you want this behavior for an array slice, just write it as a list slice: (@array)[7,0].
I am pretty sure that slicing while dereferencing with right-arrow isn't (yet) implemented in perl!
DB<71> x [qw/a b c/]->[2] # works like expected 0 'c' DB<72> x [qw/a b c/]->[1,0] # oops! 0 'a' DB<73> x [qw/a b c/]->[0,1] 0 'b'
Seems that instead to try slicing, the comma is interpreted in scalar context. Hence the last element of the slice-list is chosen as index!
UPDATE: the only way I know to slice lists like arrays is:
DB<83> x @{[ qw// ]}[0,1] 0 undef 1 undef DB<84> x @{[ qw/a b c/ ]}[0,1] 0 'a' 1 'b'
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Array/List Strangeness (why)
by tye (Sage) on Aug 05, 2009 at 18:14 UTC | |
by LanX (Saint) on Aug 05, 2009 at 18:29 UTC |