RosettaCodeData/Task/Remove-lines-from-a-file/Perl/remove-lines-from-a-file-2.pl
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

27 lines
728 B
Perl

#!/usr/bin/perl -w
use strict ;
use Tie::File ;
sub deletelines {
my $arguments = shift ;
my( $file , $startfrom , $howmany ) = @{$arguments} ;
tie my @lines , 'Tie::File' , $file or die "Can't find file $file!\n" ;
my $nrecs = @lines ;
if ( $startfrom > $nrecs ) {
print "Error! Starting to delete lines past the end of the file!\n" ;
return ;
}
if ( ( $startfrom + $howmany ) > $nrecs ) {
print "Error! Trying to delete lines past the end of the file!\n" ;
return ;
}
splice @lines , $startfrom - 1 , $howmany ;
untie @lines ;
}
if ( @ARGV != 3 ) {
print "Error! Invoke with deletelines <filename> <start> <skiplines> !\n" ;
exit( 1 ) ;
}
deletelines( \@ARGV ) ;