develooper Front page | perl.perl6.language | Postings from March 2005

pop, push, reverse, sort, and splice on a multidimensional array

Thread Next
From:
Rod Adams
Date:
March 15, 2005 00:22
Subject:
pop, push, reverse, sort, and splice on a multidimensional array
Message ID:
42369B35.4000701@rodadams.net

 my int @a is shape(Int ; Int) = (1..10 ; 2..100 :by(2) ; 4);

 $x = pop @a
 push @a, $x;
 @b = sort @a;
 # etc

I see two views to take with these cases.

1) flatten the array to one dimension, and act accordingly.

or

2) assume

  my int @a is shape(Int ; Int);
  my @a is Array of Array of int;

Mean exactly the same thing, as do

  @a[3;4]
  @a[3][4]

And then operate the Perl 5 way, where C<pop @a> would return an array ref.


#2 seems like the way to go, but I'm open to other suggestions.

I'm especially interested in hearing people's view on how C<splice> 
should work with multi-dim arrays.

-- Rod Adams



Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About