jriggs420 has asked for the wisdom of the Perl Monks concerning the following question:
So the input file can have anywhere from 1 to 100 lines, I'll never know before hand what the number will be. I've already tried 'eof' and it doesn't work because by the time it is 'true' the last line has already been modified/written. So, (A) am I going about this the totally wrong way? (B) if so, is there a better way to do this? Please keep in mind I am a novice, and would like to at least understand what is going on. And if you see any glaring defects feel free to point them out. TIA- Joeopen(TXTIN,"ARGV[0]") || die "Cannot open the data file"; open(TXTOUT,">ARGV[1]") || die "Cannot open the formatted file"; #$itercnt=0 while(<TXTIN>) {#counting number of lines in input file $itercnt++ } for ($match=0;$match<$itercnt;$match++){ while(TXTIN){ chomp $_; $_ =~ s/yada/yadda/; print TXTOUT $_; }} #for (;$match=$itercnt;$match++){ # while(TXTIN){ # chomp $_; #$_ =~ s/different/regex here/; #print TXTOUT $_; #}} # getting stuck in infinite loop in here somewhere # so I haven't been able to see if it is working close(TXTIN); close(TXTOUT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: While.For loop noob query
by Roy Johnson (Monsignor) on Oct 06, 2005 at 14:34 UTC | |
by jriggs420 (Sexton) on Oct 06, 2005 at 15:05 UTC | |
by Roy Johnson (Monsignor) on Oct 06, 2005 at 15:17 UTC | |
by ikegami (Patriarch) on Oct 06, 2005 at 15:20 UTC | |
|
Re: While.For loop noob query
by davidrw (Prior) on Oct 06, 2005 at 14:28 UTC | |
|
Re: While.For loop noob query
by Perl Mouse (Chaplain) on Oct 06, 2005 at 14:21 UTC | |
|
Re: While.For loop noob query
by blazar (Canon) on Oct 06, 2005 at 15:00 UTC | |
|
Re: While.For loop noob query
by McDarren (Abbot) on Oct 06, 2005 at 15:00 UTC | |
|
Re: While.For loop noob query
by ikegami (Patriarch) on Oct 06, 2005 at 14:34 UTC |