Hello,

I try to slice AOA into two subsets, then put them back. The problem is when I put them back, I couldn't do what I like, for example:
Here is Original array
a b 3 4
c d 2 5
e f 13 8
slice into two pieces:


print Dumper of array A
a b
c d
e f

print Dumper of array B

3 4
2 5
13 8
put them back once
Here we put two subsets back together
a b 3 4
c d 2 5
e f 13 8

So far it ok However, if I do it once more, it looks like this:
a b 3 4 a b 3 4
c d 2 5 c d 2 5
e f 13 8 e f 13 8

but I attempt to do is like this:
a b a b
c d c d
e f e f

How can I do it and where I am wrong?

Thanks,

Shiping
_______________________________________________________________________________
use strict;
use warnings;
use Data::Dumper;

my (@a, @b);
my @all =(['a', 'b', 3, 4], ['c', 'd', 2, 5], ['e', 'f', 13, 8]);

print "Original array\n";
foreach my $i (@all){
        print join " ",@{$i},"\n";
        #cut array in columns;
        my @tmp1 = @{$i}[0,1];
        push @a, [EMAIL PROTECTED];
        my @tmp2 = @{$i}[2,3];
        push @b, [EMAIL PROTECTED];
}
print "\n";

print "print Dumper of array A\n";
foreach my $k (@a){
        print join " ",@{$k},"\n";
}       
print "\n";
# print Dumper @a;

print "print Dumper of array B\n";
print "\n";
foreach my $k (@b){
        print join " ",@{$k},"\n";
}       
# print Dumper @b;

my @backcolumn1 = @a;

if (scalar @backcolumn1 != scalar @b) {
        exit(0);
} else {
        for my $i (0 .. $#backcolumn1) {
        push @{$backcolumn1[$i]}, @{$b[$i]};
    }
}
print "\n";

print "Here we put two subset arraies back together\n";
foreach my $k (@backcolumn1){
        print join " ",@{$k},"\n";
}
######################################################;
my @backcolumn2 = @a;
if (scalar @backcolumn2 != scalar @a) {
        exit(0);
} else {
        for my $i (0 .. $#backcolumn2) {
        push @{$backcolumn2[$i]}, @{$a[$i]};
    }
}
print "\n";
sleep(1);
print "Here again we put another two subset arraies back together\n";
foreach my $k (@backcolumn2){
        print join " ",@{$k},"\n";
}


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to