Cathy Gear wrote:
> 
> I have a file of names and addresses. Each name and address is over nine
> lines (including blanks). I want  to use this file in a word document as an
> address list.
> 
> My attempt so far has resulted in every line being printed nine times. Help
> please...
> 
> #!/usr/contrib/bin/perl
> # open the input file
> open(INFILE,  '<address.txt');

You should _always_ check the return value from open()

open INFILE, '<address.txt' or die "Cannot open address.txt: $!";


> # open the output
> open(OUTFILE, '>addline.txt');

open OUTFILE, '>addline.txt' or die "Cannot open addline.txt: $!";


> # read the whole file
> #While there are lines in the infile
> #For each 9 lines print the lines, print a new line, reset counter
> while(<INFILE>)
>     {
>          $ThisLine = $_;

while ( $ThisLine = <INFILE> ) {
    chomp;


>          {    for ($i = 1; $i <= 9; $i +=1)
>                 {print OUTFILE  $ThisLine; print OUTFILE ","; next}
>         }

    my @address;
    push @address, scalar <INFILE> for 1 .. 9;
    print OUTFILE join( ',', $ThisLine, @address ), "\n";


>          print OUTFILE "\n";
>          $i = 1;
>     }
> close(INFILE);
> close(OUTFILE);


John
-- 
use Perl;
program
fulfillment

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

Reply via email to