CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: Appening to EOF: Edit Log



Mortimer
journeyman

Jun 19, 2001, 7:02 AM


Views: 3105
Re: Appening to EOF

>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...


Code
$addr = $. if eof(FH);

...or not bother at all...


Code
$addr = $.;

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...


Code
local $^I = ".bak"; # the backup extension 
local @ARGV = "$filename"; # the file to edit
while(<>){
s/$_/Testing 123\n/ if eof;
print;
}

Ugly init?

Cheers,
Dave.
www.dmscripts.com
davemortimer@bigpond.com



(This post was edited by Mortimer on Jun 19, 2001, 6:09 AM)


This post has not been edited


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives