On Thu, Sep 01, 2005 at 05:41:36PM -0700, Yitzchak Scott-Thoennes wrote: > On Wed, Aug 31, 2005 at 06:07:11AM -0700, japhy @ perlmonk. org wrote: > > In 'perlref', item #3 of 'Using References' says > > > > One more thing here. The arrow is optional between brackets sub- > > scripts, so you can shrink the above down to > > > > $array[$x]{"foo"}[0] = "January"; > > > > This led me to believe I could write: > > > > sub foo { ...; return @data } > > > > my $x = (foo())[0][1]; > > > > which would have the same effect as > > > > my @return = foo(); > > my $x = $return[0][1]; > > > > However, it's a syntax error. This can be fixed with an arrow: > > > > my $x = (foo())[0]->[1]; > > > > The problem is that (foo())[0] is NOT analogous to $array[$x]; one is a > > list slice, the other is a single element from an array. But the > > documentation does not distinguish when it says "optional between brackets > > subscripts [sic]". > > > > I think the language there should be polished a bit. > > I don't see any reason not to just make it legal syntax instead: > > --- p/perly.y.orig 2005-06-08 01:32:12.000000000 -0700 > +++ p/perly.y 2005-08-31 11:02:57.520643200 -0700 > @@ -487,6 +487,10 @@ subscripted: star '{' expr ';' '}' > | subscripted '(' ')' /* $foo->{bar}->() */ > { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, > newCVREF(0, scalar($1))); } > + | '(' expr ')' '[' expr ']' /* list slice */ > + { $$ = newSLICEOP(0, $5, $2); } > + | '(' ')' '[' expr ']' /* empty list slice! */ > + { $$ = newSLICEOP(0, $4, Nullop); } > ; > > /* Binary operators between terms */ > @@ -622,10 +626,6 @@ term : termbinop > { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, > OP_AV2ARYLEN));} > | subscripted > { $$ = $1; } > - | '(' expr ')' '[' expr ']' /* list slice */ > - { $$ = newSLICEOP(0, $5, $2); } > - | '(' ')' '[' expr ']' /* empty list slice! */ > - { $$ = newSLICEOP(0, $4, Nullop); } > | ary '[' expr ']' /* array slice */ > { $$ = prepend_elem(OP_ASLICE, > newOP(OP_PUSHMARK, 0), > End of Patch.
Any other feedback on making (LIST)[LIST]-> not need the ->?