On Wednesday, October 15, 2003, at 04:23 PM, Kevin Old wrote:

Hello everyone,

I have a multidimensional array that I need to split into 4
multidimensional arrays.  I've tried the examples from the Programming
Perl 3rd ed. Chapter 9 for splicing Arrays of Arrays and am not having
any luck.

Here's an example of how my data looks:

[1 2 3 4 5 6 7 8 9 10 11 12]
[A B C D E F G H I J  K  L]

Here's how I need it to look:

[1 2 3 4]       [5 6 7 8]
[A B C D]       [E F G H]

[9 10]          [11 12]
[I J]           [K  L]

Hmm, I'm a little lost at this point.


The code I used

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

my @AoA = ();
        push @AoA, qw[1 2 3 4 5 6 7 8 9 10 11 12];
        push @AoA, qw[A B C D E F G H I J K L];

This isn't an array of arrays at this point. Just want to make sure you know that. It's one long array with 1 - 12 at the front and A - L at the back.


If you meant for this to be a multidimensional array, try:

my @AoA = ( [ 1..12 ], [ 'A'..'L' ] );

print Dumper([EMAIL PROTECTED]);

This would show that, if it was compiling.


my @newAoA = ();
for (my $startx = my $x = 4; $x <= 8; $x++) {
            for (my $starty = my $y = 7; $y <= 12; $y++) {
            $newAoA[$x - $startx][$y - $starty] = $AoA[$x][$y];
        }
}

Obviously this code doesn't work. It's a referencing issue. I would try to correct it, but I don't understand the goal. Can you try taking another stab at explaining how the array should look in the end?


James

print @newAoA;


The error I got is:


Can't use string ("5") as an ARRAY ref while "strict refs" in use at
./splice.pl line 16.


Any ideas?


Thanks in advance for any help!

--
Kevin Old <[EMAIL PROTECTED]>


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to