in reply to build multidimensional array from arrays

kevsurf check out the following code:

use Data::Dumper; @one = qw(A B C D); @two = qw(E F G H); @mda=( [@one],[@two]); print Dumper(\@mda);

When run yields:

$VAR1 = [ [ 'A', 'B', 'C', 'D' ], [ 'E', 'F', 'G', 'H' ] ];

Was that what you were after?


Peter L. Berghold -- Unix Professional
Peter at Berghold dot Net
   Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.

Replies are listed 'Best First'.
Re: Re: build multidimensional array from arrays
by kevsurf (Acolyte) on Jan 29, 2004 at 18:40 UTC
    Well, no that wasn't what I was looking for, but it's a nice piece of code to add to my arsenal. That basically puts the contents of @one in the first *row* of the @mda, @two in the second *row*. I want it to go in @mda in the *columns*. So...
    $mda[0][0] = A; $mda[0][1] = B; so forth... $mda[1][0] = E; $mda[1][1] = F; so forth...

    A little background on why I want to do this is that I'm formatting data in arrays to that I can send the Spreadsheet::WriteExcel module a reference to an MDA so that it writes the spreadsheet "contents" from one call to
    $ws->write(0, 0, \@mda); #writes all data into spreadsheet

    Thanks,
    Kevin

      In that case, it's even easier:

      my @mda = ( [ @one ], [ @two ] );

      Update: Or, of course, to save a bit of typing:

      my @mda = \( @one, @two );

      dave