Patricia E Gorden-Ozgul wrote:
> 
> 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:
> 
> [snip code]


This will do what you want:

#!/usr/bin/perl -w
use strict;

# 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 or die "Can't open data file: $datafile\nBecause: $!";

use POSIX qw/strftime/;
my $date = strftime '%Y%m%d', localtime;

# define formats for printf statements
my $fmt1 = '  %-16s%-8s%-10s' . ' ' x 17 . '%-11s' . ' ' x 152 . '%-10s' . ' ' x 16 . 
"01\n";
my $fmt2 = '  %-10s' . ' ' x 10 . '%-10s    %-12s%-10s' . ' ' x 184 . "02\n";
my $fmt3 = '  %-10s500500%-10s%-10s%-8s%-6sSPMAT340' . ' ' x 182 . "03\n";

my $second_pass = 0;
while ( <DATA> ) {
    chomp;
    my @data = split /\|/;
    my $count = $data[7];
    unless ( $second_pass ) {
        printf $fmt1, @data[4,5,9], $date, $data[6];
        printf $fmt2, @data[11,10,6,7];
    }
    printf $fmt3, @data[11,2,10], $date, $data[1];

    $second_pass = $count - 1 unless $second_pass--;
}
close DATA;
exit 1;



John
-- 
use Perl;
program
fulfillment

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

Reply via email to