Help for this page

Select Code to Download


  1. or download this
    my $MAXLINES=20; # not including header
    open my $fh, '+<', 'foo.txt' or die $!;
    ...
    seek $fh, 0, 0 or die "seek failed";
    print $fh @lines;
    close $fh;
    
  2. or download this
    use Tie::File;
    my $MAXLINES=20; # not including header
    ...
    splice @lines, 1, @lines-$MAXLINES if @lines>$MAXLINES;
    push @lines, "newline\n";
    untie @lines;