develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #118089] Feature: list slices to the end

Thread Next
Father Chrysostomos via RT
July 7, 2013 00:36
[perl #118089] Feature: list slices to the end
Message ID:
On Sun Jun 09 06:55:59 2013, wrote:
> For the record, I am open to a patch to provide this kind of change,
> and am not
> particular as to which of the suggestions is used, as long as the work
> is
> sound.

Of the two suggestions, I think $# is best.  If list and array slices
could record the length in an interpreter variable localised to the
brackets on the right, $# could be a magical variable accessing that.

That would make all three of these work:

# Omit the first element
@a = (gimme_list())[1..$#];
@a = @b[1..$#];
sub end { $# }
@a = (gimme_list())[1..end];

Do we want that?

As for the [1..] suggestion, would that be a postfix .. operator applied
to the 1?  Or would ..] be a special way to end the subscript?  I.e.,
should [5.., 2] be allowed or not?  And if we can access this number,
why restrict it to ranges?


Father Chrysostomos

via perlbug:  queue: perl5 status: open

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About