develooper Front page | | Postings from September 2000

RFC 206 (v1) Array: @#arr for getting the dimensions of an array

Thread Next
Perl6 RFC Librarian
September 8, 2000 15:40
RFC 206 (v1) Array: @#arr for getting the dimensions of an array
Message ID:
This and other RFCs are available on the web at

=head1 TITLE

Array: @#arr for getting the dimensions of an array

=head1 VERSION

  Maintainer: Buddha Buck <>
  Date: 8 September 2000
  Mailing List:
  Number: 206
  Version: 1
  Status: Developing


This RFC proposes the use of the @# prefix to get the bounds and
dimensionality of a multidimensional array.


The $#array notation is useful for getting the upper bound of a
unidimensional array, but is not as useful for getting the upper bounds of
a multidimensional array. A multidimensional array should have a list of
upper bounds, not a single upper bound.

This RFC proposes using @#array, analogous to $#array, to get the list of
upper bounds for a multidimensional array @array. The length of @#array
would indicate the dimensionality of @array.

=head2 Example

  sub printbounds (\@) {
    my $arrayref = shift;
    my $array = @$arrayref;
    print "D:", scalar @#arrayref," B:(",join(',',@#arrayref),")\n";

  my int @a :bounds(2,2,2,2,2);
  printbounds(@a); # "D:5 B:(2,2,2,2,2)\n"

  my int @b :bounds(@a); # create @b the same size as @a
  printbounds(@b); # "D:5 B:(2,2,2,2,2)\n"
  my @c = (1,2,3,4,5,6,7,8,9,10);
  printbounds(@c); # "D:1 B:(9)\n"


Presumably, multidimensional arrays would have to store their bounds
somewhere to have the semantics provided in RFC 203. This operator would
simply return to the user those stored bounds.

Where an array is declared without ':bounds', @# returns the largest
bounds of each dimension that has been accessed:

  my int @d = ();
  $d[[3,4]] = 5;
  @e = @#d;        # (3,4)


RFC 203: Notation for declaring and creating arrays

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