in reply to removing lines that are in the end of a file
truncate combined with tell seems to be pretty straight-forward:
open my $fh, '+<', 'test.txt' or die $!; my $last_matched = 0; my $told = 0; while( my $line = <$fh> ) { my $matched = $line =~ m/SIL$/; truncate $fh, $told and last if $matched && $last_matched; $last_matched = $matched; $told = tell $fh; } close $fh or die $!;
Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: removing lines that are in the end of a file
by BrowserUk (Patriarch) on Apr 05, 2013 at 15:46 UTC | |
by davido (Cardinal) on Apr 05, 2013 at 15:50 UTC | |
by BrowserUk (Patriarch) on Apr 05, 2013 at 16:10 UTC |
In Section
Seekers of Perl Wisdom