in reply to truncate only a last blank line
#! usr/bin/perl opendir(FILES,".")||die "Cannot open files in the directory\n"; @files=(); for(readdir(FILES)){ if($_=~/\.txt/){ push(@files, $_); } } print "@files\n"; for $i(0..$#files){ print "working on $files[$i]\n"; open (FH, "+<$files[$i]") or die "can't update $file: $!"; my $linevalue; while ( $linevalue = <FH> ) { $addr = tell(FH) unless eof(FH); last if (eof(FH)); } if($linevalue eq "\n") { truncate(FH, $addr) or die "can't truncate $file: $!"; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: truncate only a last blank line
by hj4jc (Beadle) on Dec 29, 2005 at 15:35 UTC |