At 11:27 2002.04.19, [EMAIL PROTECTED] 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'); ># open the output >open(OUTFILE, '>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 = $_; > { for ($i = 1; $i <= 9; $i +=1) > {print OUTFILE $ThisLine; print OUTFILE ","; next} > } > print OUTFILE "\n"; > $i = 1; > } >close(INFILE); >close(OUTFILE); > > > > >Cathy
This is because you read the line only in your while loop and not in your for loop. This should work better: while(<INFILE>) { for(my $i=1;$i<=9;$i++) { # print the courent line (store in $_) print OUTFILE; # exit the loop if no more lines last if eof; # read the next line $_ = <INFILE>; } } If you want to put a "," at the end of every line, you will have to remove the "\n", add your "," and then put a "\n" back at the end of the line like this: chomp; # remove EOL char from $_; print OUTFILE "$_,\n"; Hope this helps. >Cathy Gear >e-mail: [EMAIL PROTECTED] > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] ---------------------------------------------------------- Éric Beaudoin <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]