Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Replacing Lines in a File

by Stevie-O (Friar)
on May 26, 2004 at 19:52 UTC ( #356711=note: print w/ replies, xml ) Need Help??


in reply to Replacing Lines in a File

As punkish has said, there's no way to do it other than by rewriting the entire file after where you're modifying. However, there are things that can severely reduce the actual amount of stuff you have to code to accomplish that. For your specific example, the -lpe -i.bak oneliner is probably the easiest. Here's an example of something using Tie::File, which allows you to treat a file as an array of lines (change the array, change the file).

tie @array, 'Tie::File', '/data/syslog/log.backup' or die "Damnit, Jim +, he's dead: $!"; s/$ip/$txt/ for @array;
--Stevie-O
$"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc


Comment on Re: Replacing Lines in a File
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-12-25 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (162 votes), past polls