If you don't want to read the whole file into memory you can just truncate it in place....
[tachyon@www cgi-bin]# cat ./test.pl #!/usr/bin/perl my $file = '/tmp/test.txt'; open FILE, ">$file" or die $!; print FILE "foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar +\n\n\r\n\n\r"; close FILE; # grab the last 20 bytes for analysis open FILE, $file or die $!; { local $/ = undef; seek FILE, -20, 2; $EOF = <FILE>; } close FILE; my $file_length = -s $file; (my $newlines) = $EOF =~ m/([\015\012]+)\z/; my $num_newlines = length $newlines; print "File length $file_length bytes, number of newlines $num_newline +s\n"; truncate $file, ($file_length - $num_newlines) or die $!; print "Now file is ", -s $file, "bytes\n\n"; [tachyon@www cgi-bin]# ./test.pl File length 53 bytes, number of newlines 6 Now file is 47 bytes [tachyon@www cgi-bin]#
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
In reply to Re: New Line at End File
by tachyon
in thread New Line at End File
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |