in reply to truncate only a last blank line

It's fast, but doesn't do what you want..

This may be a silly question, but what about using the File::ReadBackwards module? It has a 'tell' function, which should give you the value for the file pointer at the beginning of the last line which has been read. With this information, use truncate to trim off the unwanted line. (When I get a test case, I'll post my (probably hideously ugly) sample code)

Alternatively, you could do this (which qualifies as ugly)

open(FILE, $file) or die "$file could not be opened because $!\n"; @slurp = <FILE>; close(FILE); pop(@slurp) if $slurp[-1] =~ /^\s*$/; open(FILE, "> $file") or die "$file could not be opened because $!\n"; print FILE @slurp; close(FILE);

I did say it was ugly...

emc

" When in doubt, use brute force." — Ken Thompson