List,

I got an answer elsewhere and thought I'd share it -

...
...
...
my $newdata = 1;
my $counter = 0;
while(<DATA>) {
    chomp;
    my @data = split('\|');
    if($newdata) {
        $newdata = 0;
        if($data[7] == 1) {
            $counter = 1;
        } elsif($data[7] == 2) {
            $counter = 2;
        } elsif($data[7] == 3) {
            $counter = 3;
        }
...
...
and at the end of the 3rd printf...
 
    $counter -= 1;
    $newdata = 1 if(! $counter);
}
close DATA;
exit 1;

It may not be pretty but it gets the job done.
Hope it's useful to someone.

BTW - I'm really good at conversing with myself, eh?
Pat G-O

>  -----Original Message-----
> From:         Gorden-Ozgul, Patricia E  
> Sent: Tuesday, March 18, 2003 4:42 PM
> To:   '[EMAIL PROTECTED]'
> Subject:      RE: Data Read/Loop/Print Problem
> 
> I suspect I need to initially read all my data into the hash up front, in
> order to do what's necessary.  I'd need to be able to know which record I
> was on in order to read the next.
> 
> So how would I read the entire input file into a hash and print where
> appropriate.
> Anyone?
> 
> Pat
> 
>        -----Original Message-----
>       From:   Gorden-Ozgul, Patricia E  
>       Sent:   Tuesday, March 18, 2003 3:36 PM
>       To:     '[EMAIL PROTECTED]'
>       Subject:        Data Read/Loop/Print Problem
> 
>       I need to modify my code to test the value stored in the 8th
> position of the input.
> 
>       Here's the input file:
> 
>       ...
>       ...
>       04500|04500|61.89|1|182988|20021023|61.89|1|0|0000070001|17893|FIRM|
>       
> 06156|06156|161.92|1|183774|20021115|566.72|3|0|0000070001|20591|FIRM|
>       
> 06277|06277|323.84|2|183774|20021115|566.72|3|0|0000070001|20591|FIRM|
>       
> 06265|06265|80.96|3|183774|20021115|566.72|3|0|0000070001|20591|FIRM|
>       
> 09310|09310|94.46|1|183719|20021126|165.52|2|0|0000070001|22532|FIRM|
>       
> 09310|09310|71.06|2|183719|20021126|165.52|2|0|0000070001|22532|FIRM|
> 
> 
>       If the value is 1, after printing the 1st and 2nd printf statements,
> pass it through the 3rd printf statement, producting 3 output records.
> 
>       If it is 2, after printing the 1st and 2nd printf statements, pass
> it and the next input record through the 3rd printf statement, producing 4
> output records.
> 
>       If it is 3, after printing the 1st and 2nd printf statements, pass
> it and the next 2 input records through the 3rd printf statment, producing
> 5 output records.
> 
>       ...and so on.
> 
>       Here's my code:
> 
>       #!/usr/bin/perl -w
>       #
>       # Parse input from invoice file and split into three output files
>       # PGO March 2003
>       # must run inv_sed against datafile (file9.final) to remove $
> 
>       my $datafile = "invshrt";
>       open DATA, "< $datafile" || die "Can't open data file: $datafile";
>       # my $date = `date +%Y%m%d`;
> 
>       my $date = do {
>           my @ymd=(localtime(time))[5,4,3];
>           $ymd[0] += 1900;
>           $ymd[1] += 1;
>           sprintf "%04d%02d%02d", @ymd;
>       };
> 
>       while(<DATA>) {
>           chomp;
>           my @data = split('\|');
>           printf "%-2s%-16s%-8s%-10s%-10s%-7s%-11s%-152s%-10s%-16s%-2s\n",
>               "",
>               $data[4],
>               $data[5],
>               $data[9],
>               "",
>               "",
>               $date,
>               "",
>               $data[6],
>               "",
>               "01";
>           printf "%-2s%-10s%-10s%-10s%-4s%-12s%-10s%-184s%-2s\n",
>               "",
>               $data[11],
>               "",
>               $data[10],
>               "",
>               $data[6],
>               $data[7],
>               "",
>               "02";
>           printf "%-2s%-10s%-6s%-10s%-10s%-8s%-6s%-10s%-180s%-2s\n",
>               "",
>               $data[11],
>               "500500",
>               $data[2],
>               $data[10],
>               $date,
>               $data[1],
>               "SPMAT340",
>               "",
>               "03";
>       }
>       close DATA;
>       exit 1;
> 
>       Perhaps some code before the 3rd printf akin to (pseudo-code
> follows):
>               ...
>               ...
>               read
>               store in hash
>               ...
>               printf (the 1st);
>               printf (the 2nd);
>               ...
>               if $data[7] = 1
>                       printf (the 3rd );
>               else if $data[7] = 2
>                       printf (the 3rd);
>                       read next input rec;
>               else if $data[7] = 3;
>                       printf (the 3rd);
>                       read next input rec;
>                       printf (the 3rd);
>                       read next input rec;
>                       printf (the 3rd);
> 
>       I'm looking for syntax if possible.
>       Thanks with regards.
>       Pat Gorden-Ozgul
>               
> 
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to