in reply to How do I modify a single line in a file?
I would like to modify a line in the /etc/passwd (gcos) file after I've found it...WITHOUT the use of modules (so it can be used on a fresh perl install
Now we wouldn't be trying to make a hacking tool now would we?
FYI - A Fresh PERL install comes with a lot of handy modules included.
Here's a hint, start with:
open(FH, "< $filename") or die ("Can't read file: $!\n"); @the_file = <FH>;
Then you could play with the contents of @the_file & write the whole thing back out again. (Assuming you close and open(FH, "> $filename") again.
Now AFAIK the IO module installs with a basic PERL installation. So a better way to do this might be:
use IO::File; $fh = IO::File->new($filename, "r+") or die "Couldn't open $filename for read & write: $!\n";
I hope I have been of some useful guidance...
|
|---|