On Tue, Feb 10, 2009 at 11:13, Rob Canning <robcann...@eircom.net> wrote:
> hi,
>
> i am trying to copy a three dimensional array to a two dimentional one
>
> this:
>
> @AoA = ( [2, 3], [4, 5, 7], [0] );
>
> to this
>
> @A = qw(2 3 4 5 7 0);
>
> i know the answer is staring at me in perldoc perldsc but i cant see it!
snip

These are a two dimensional array and a one dimensional array, not 3d
and 2d.  What you want is called flattening. you can flatten easily by
referencing each element of @AoA.  I would use a map to do this:

my @array = map { @$_ } @AoA;

You could also use a for loop:

my @array;
for my $arrayref (@AoA) {
    push @array, @$arrayref;
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to