in reply to Array/List Strangeness
Another two cases:
{ my @b; my @a = @b[1,0]; print Dumper(\@a); # $VAR1 = [ undef, undef ] } { my @b; my @a = (@b)[0]; print Dumper(\@a); # $VAR1 = [] }
The first makes sure that it is not about slices vs. non-slices
The second shows that it really is about lists vs. arrays. And also that it is an inconsistency that matters in real code (unlike the academic example ()[0] )
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Array/List Strangeness
by LanX (Saint) on Aug 05, 2009 at 17:29 UTC | |
by jethro (Monsignor) on Aug 05, 2009 at 20:26 UTC | |
by tye (Sage) on Aug 05, 2009 at 18:48 UTC |