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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.