Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Skipping lines

Status
Not open for further replies.

newbie425

Programmer
Jan 27, 2003
16
US
I have to process a data file that looks pretty ugly, in other words a record has data on multiple lines. I need to skip lines to retreive the information I need.

I've used so many different combinations of if statements and while loops, but nothing worked.

If this sounds trivial to you, please don't laugh, this is my first perl program. I have to finish it by Jan 31st because we're going to production Feb 1st.

Any help is greatly appreciated.

Thanks!
 
It varies, either one or two lines.

I'm processing a file of accounts. I need to retreive the name of a product and plan. The file layout doc tells me that the name of a product is in detail record 2(which turns out to be the 3rd line), so the file looks like:
-------------------------------------------------------
R1234567890100 John Doe ............
.............. 9876538905......... Blah Blah Blah.....
Term Life
00000000000000000000.................
R9876543210200 etc....
Annuity
--------------------------------------------------------

I need to extract "Term Life" (skip 2 lines for insurance) and "Annuity" (skip one line for annuities).

Thank you!
 
Sorry I made a mistake...

The file layout doc tells me that the name of a product is in detail record 2(which turns out to be the 3rd line) For An Insurance Product
 
The "R" in front of an account number and the 4 digit asset type signals a new record.

A record can be 10 lines long. There can be many details. I'm interested in the line that contains the Product name. Furthermore I need the plan name too, but i need to conquer product name first.

Does this make sense?
 
What denotes that a line contains a "product name"? Is it always the third line from the R####? ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Its not always the third line.

The flow of my script is first I check if there is an R in the first field of the line, then check the type of policy and increment the count, then the product and increment the count, then the plan name and increment the count. Sounds simple enough if only the data file wasn't confusing. I have the file layout so I know where the data is on the line, just need to get to that line.

if ($input_type eq "R") {
if ($asset_type eq "0100") { # "0100" for life policy
counter;
- if it is, this is where i want to go to the third line to read the product name and do a count on that too)}

elsif ($asset_type eq "0200") { # "0200" for annuity policy
counter;
- same as life }

elsif ($asset_type eq "0300") { # "0300" for pension policy
counter;
- go to next line to read product }
}

It gets even more ugly because the plan name is on the line before the product name so I have to go back too.

Thanks again for your help.
 
I don't understand why you need the asset name. If the asset type uniquely specifies the product then there is no reason to try to parse the rest of the record just to get the name of the asset. Just use a lookup table (a hash) that uses the asset type lookup the asset name
Code:
my %assets = {
        '0100'  => 'Term Life',
        '0200'  => 'Annuity',   
        '0300'  => 'Pension',   
);
# Initialize counter
my %counter = (
        'Term Life' => 0,
        'Annuity'   => 0,
        'Pension'   => 0,
);

...

if ($input_type eq "R") {
    $counter{ $assets{$asset_type} }++;
}
Or just key the counter off the asset type directly
Code:
my %counter = (
        '0100'   => 0,
        '0200'   => 0,
        '0300'   => 0,
);

...

if ($input_type eq "R") {
     $counter{$asset_type}++;
}

...

#print out totals
for (keys %assets) {
     print "Number of asset $assets{$_}: $counter{$_}\n";
}
Something like that.

jaa
 
The asset type and the product name are 2 different things. An annuity is an asset type. I retreive the asset type from a four digit ID code (0200). ABC and DEF are Annutiy products. 123 and 456 are plans under product ABC. There is no ID for the products and plans. They are strings.

I will try your logic. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top