Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Table building confusion Help Wanted

by PrakashK (Pilgrim)
on Jan 16, 2002 at 03:59 UTC ( #139096=note: print w/ replies, xml ) Need Help??


in reply to Table building confusion Help Wanted

To address your question #1 first: You forgot to reset $i to 0 before moving on to the next record. Add:

$i = 0;
at the end of the loop where you are reading from the array and printing the values out.

Having said that, I'd use array of hashes instead of array of arrays to store such data. Hashes lend themselves very nicely for storing records.

#!/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 $count = 3; my @major_PER_Data; # save it for (0 .. $count - 1) { push @major_PER_Data, { ID => $dataA[$_], CUST => $dataB[$_], SSN => $dataC[$_], RELATION => $dataD[$_], }; } # print it for my $PER_item (@major_PER_Data) { print "$PER_item->{ID}\n"; print "$PER_item->{CUST}\n"; print "$PER_item->{SSN}\n"; print "$PER_item->{RELATION}\n"; }
Much smaller and clearer.

/prakash


Comment on Re: Table building confusion Help Wanted
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://139096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (14)
As of 2014-10-02 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (61 votes), past polls