Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: reading/writing line by line

by Biker (Priest)
on May 22, 2002 at 15:14 UTC ( #168463=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: reading/writing line by line
Download Code
Re: Re: reading/writing line by line
by amarceluk (Beadle) on May 22, 2002 at 15:44 UTC
    Your suggestion did work; thank you! Now I'm trying to apply the same principle to finding and replacing text.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://168463]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2015-07-06 03:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (69 votes), past polls