Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Writing and modifying (change ordelete) a file

by splinky (Hermit)
on Jul 16, 2000 at 09:06 UTC ( [id://22756]=note: print w/replies, xml ) Need Help??


in reply to Writing and modifying (change ordelete) a file

The short answer is that you have to rewrite the whole file. You can't modify stuff in place.

The slightly longer answer is that you can modify files in place, but you can't alter the length of the file at all.

Of course, Perl makes rewriting the whole file really easy, especially with the -i and -p command-line switches. Something like the following might do what you want:

perl -i -pe 's/(user):.*?:/$1:passwd:/' filename

*Woof*

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found