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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.