What exactly is intended by the recursive reference:
$FirstItem[$FirstItem[$Index]]
That seems kind of unusual.
As mentioned,
unpack would do the job for you quite
well, but even better would be to use a multi-dimensional
array, or Array of Arrays (AoA), or even an Array of Hashes (AoH). AoH allows you to label
the fields. AoA is probably more compact.
Consider:
sub Read_File
{
while(<CLAIMS>)
{
# (Choose one method only)
# 1: AoH method
my (%row);
@row{'a','b','c'} = unpack ("A8 A6 A2", $_);
push (@data, \%row);
# 2: AoA method
push (@data, [unpack ("A8 A6 A2", $_)]);
}
}
So you can extract records like so:
my ($record) = $data[$n]; # Index starts at 0, not 1
# AoH
print "$record->{a} | $record->{b} | $record->{c}\n";
# AoA
print "$record->[0] | $record->[1] | $record->[2]\n";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.