Jun 19, 2001, 7:02 AM
>This is seeking the last line number, and this works...
>$addr = $. unless eof(FH);
No it doesn't. This will assign the penultimate value of $. to $addr because the invisible eof character resides on the last line. You can say...
...or not bother at all...
If you use the unless, your inplace edit will place the line before the last line in your file. You also have the lone print statement in the wrong place. But anyway, there's no need for the prior open of your file, you can do the lot in your inplace edit. Your code adjusted...
local $^I = ".bak"; # the backup extension
local @ARGV = "$filename"; # the file to edit
s/$_/Testing 123\n/ if eof;
(This post was edited by Mortimer on Jun 19, 2001, 6:09 AM)