in reply to Re: Array/List Strangeness
in thread Array/List Strangeness

The idiom is somewhat useful: my @a= (@b)[0..99]; would create a new array of max size 100, but won't make the new array larger if @b has fewer than 100 elements. And since there is probably code out there using this I don't think this inconsistency can be changed

I don't know what you mean, can't see any general difference between slicing @b or (@b), except when $#b==0!

DB<38> @b=1..3 DB<39> x @b[0..6] 0 1 1 2 2 3 3 undef 4 undef 5 undef 6 undef DB<40> x (@b)[0..6] 0 1 1 2 2 3 3 undef 4 undef 5 undef 6 undef

now 0-element array!

DB<43> @b=() DB<44> x @b[0..6] 0 undef 1 undef 2 undef 3 undef 4 undef 5 undef 6 undef DB<45> x (@b)[0..6] empty array

Cheers Rolf

Replies are listed 'Best First'.
Re^3: Array/List Strangeness
by jethro (Monsignor) on Aug 05, 2009 at 20:26 UTC

    Look at the time the node was posted, it was when I still had hope ;-) and no indication of further inconsistent behaviour

Re^3: Array/List Strangeness (out-of-bounds)
by tye (Sage) on Aug 05, 2009 at 18:48 UTC

    You have to make all of the elements referenced out-of-bounds. Compare @b[@b,1+@b] vs (@b)[@b,1+@b] (whether @b is empty or not).

    - tye