NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Table building confusion Help Wanted
by foogod (Friar) on Jan 16, 2002 at 06:08 UTC

    Well I can perform your desired operation with the following code:

    #!/usr/bin/perl-Tw use strict; my @dataA = ("A1", "C1", "S1"); my @dataB = ("007", "008", "005"); my @dataC = ("999-99-9999", "888-88-8888", "777-77-7777"); my @dataD = ("self", "spouse", "son"); my @array2; for (my $i=0;$i<3;$i++) { my @array1 = ($dataA[$i],$dataB[$i],$dataC[$i],$dataD[$i]); push @array2, [@array1]; } foreach my $r (@array2) { foreach my $p (@{$r}) { print $p . "\n"; } }

    You might consider looking at a hash of arrays 1977 using the following code

    my %dramatis_personae = ( humans => [ 'hamnet', 'shakespeare', 'robyn', ], faeries => [ 'oberon', 'titania', 'puck', ], other => [ 'morpheus, lord of dreams' ], ); Access it like this: foreach my $group (keys %dramatis_personae) { print "The members of $group are\n"; foreach (@{$dramatis_personae{$group}}) { print "\t$_\n"; } }

    I wish I could point to the specific area where you are having problems, but I have to get home for dinner.

    I will check back later tonight and analyze your code if another (smarter) monk hasn't already done so.

    Best of luck!

    - f o o g o d

Re: Table building confusion Help Wanted
by jlongino (Parson) on Jan 16, 2002 at 06:22 UTC
    The problem, if I understand your code correctly, is that you should move your last initialization of $i inside the foreach loop:
    my $i = 0; foreach my $PER_item (@major_PER_Data) { foreach my $PER_subitem (@{$PER_item}) { $PER_Item[$i] = $PER_subitem; $i++ } $PER_Entity[$Num_OF_PER] = $PER_Item[0]; $PER_Customer_ID[$Num_OF_PER] = $PER_Item[1]; $PER_SSN[$Num_OF_PER] = $PER_Item[2]; $PER_Relationship[$Num_OF_PER] = $PER_Item[3]; print "$PER_Entity[$Num_OF_PER] \n"; print "$PER_Customer_ID[$Num_OF_PER] \n"; print "$PER_SSN[$Num_OF_PER] \n"; print "$PER_Relationship[$Num_OF_PER] \n"; $Num_OF_PER++; }
    Should be:
    foreach my $PER_item (@major_PER_Data) { my $i = 0; foreach my $PER_subitem (@{$PER_item}) { $PER_Item[$i] = $PER_subitem; $i++ } $PER_Entity[$Num_OF_PER] = $PER_Item[0]; $PER_Customer_ID[$Num_OF_PER] = $PER_Item[1]; $PER_SSN[$Num_OF_PER] = $PER_Item[2]; $PER_Relationship[$Num_OF_PER] = $PER_Item[3]; print "$PER_Entity[$Num_OF_PER] \n"; print "$PER_Customer_ID[$Num_OF_PER] \n"; print "$PER_SSN[$Num_OF_PER] \n"; print "$PER_Relationship[$Num_OF_PER] \n"; $Num_OF_PER++; }
    As for the DBI question, that is not my forte. Perhaps someone else can help on that issue.

    --Jim