in reply to reading/writing line by line
I understood that your need is to read a file, line by line, and if the line is not blank, write the line to the output file. Did I understand that correctly?
My code snippet, as you have quoted above, will:
- Read one line from the input file
- Remove a potential newline from the end of the line
- Look if the line is now empty (zero length)
- If empty, read next line
- If not empty, write the line and a newline to the output file and then read next line from the input file
- Repeat until no more lines in input file
What part is not working as expected?
Update:
I admit, I missed the words:
"...specifically for finding and replacing all occurences of a string..."
Of course, you're right. ;-) That's what I get for answering a question while on the run to go home. ;-)
while(<IN_FILE>) s/from/to/g; print OUT_FILE; }
should do it.
Everything went worng, just as foreseen.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: reading/writing line by line
by amarceluk (Beadle) on May 22, 2002 at 15:44 UTC |
In Section
Seekers of Perl Wisdom