in reply to Editing Contents of a File

The problem is you aren't 'print'ing to the file anywhere.

The Perl Cookbook p.243-244 recipe 7.10 shows "Modifying a File in Place with -i Switch" - you basically open the file with "+<", read the whole file into an array, update the array, then rewrite the file and truncate it to its current seek pointer:

open(FH, "+< FILE") or die "Opening: $!"; @ARRAY = <FH>; # change ARRAY here seek(FH,0,0) or die "Seeking: $!"; print FH @ARRAY or die "Printing: $!"; truncate(FH,tell(FH)) or die "Truncating: $!"; close(FH) or die "Closing: $!";
If you don't mind using a temporary file, there's another recipe in the same section.

HTH.

Replies are listed 'Best First'.
Re^2: Editing Contents of a File
by bivouac (Beadle) on Jun 21, 2004 at 17:09 UTC
    I'm such a dolt! I posted this message and then looked in my Cookbook and BOOM there it was! The Cookbook's recipe 7.10 is great but I think I'm going to go down the route of create a temp file. Thanks for the insight this was very helpful and this is the reason that I keep coming back to the Monks when I'm stuck.