develooper Front page | | Postings from September 2000

RFC 191 (v1) smart container slicing

Perl6 RFC Librarian
September 1, 2000 13:56
RFC 191 (v1) smart container slicing
Message ID:
This and other RFCs are available on the web at

=head1 TITLE

smart container slicing

=head1 VERSION

  Maintainer: David Nicol <>
  Date: 1 September 2000
  Mailing List:
  Version: 1
  Number: 191
  Status: Developing


a more concise syntax for matching all the elements in a container that
are stored under keys that meet a condition


What if, instead of requiring

	@onesIwant = @hash{grep /restriction on keys/ keys %hash};

one could simply write

	@onesIwant = @hash{/restriction on keys/};

to obtain a list of all items stored in C<hash> under keys containing
the string C<'restriction on keys'>


When interpreting the appearance of a single regex (including an object
resulting from a C<qr//>) inside braces indicating container lookup,
in a "slicing" context, the regex is applied to the keys of the container
and the matching elements are returned, as per the longer syntax involving
an intermediate anonymous array.


In situations where one wants to pull a list of one item
out of a hash in which that item is keyed with a regex, assuming such
is possible, one will need to use

	@listofoneitem = ( $hash{$regex} );

instead of the syntax appropriated by this suggestion.


With the addition to the language of regular expression syntax to
deal numbers by value rather than is done now, the syntax described
in this document may provide a concise way to slice multidimensional

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