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. BTW, cygwin only has bison 1.875b, not the allowed 1.875 or 1.875c, but it seemed to work. I also note that Debian stable has 1.875d; would it make sense to just allow any 1.875* version? --- p/regen_perly.pl.orig 2005-05-07 04:36:14.000000000 -0700 +++ p/regen_perly.pl 2005-08-31 11:16:02.869920000 -0700 @@ -65,7 +65,7 @@ # the test below to allow that version too. DAPM Feb 04. my $version = `$bison -V`; -unless ($version =~ /\b(1\.875c?|2\.0)\b/) { die <<EOF; } +unless ($version =~ /\b(1\.875[a-z]?|2\.0)\b/) { die <<EOF; } You have the wrong version of bison in your path; currently 1.875 or 2.0 is required. Try installing End of Patch.