Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 surveying the Monastery: (9)
As of 2014-09-16 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (157 votes), past polls