This should run at least a bit faster than your version since it doesn't concern itself with end-of-lines at all. Depending on how smart Tie::File is, it may be a whole lot faster - though as far as I know Dominus put some effort into making it clever. Still, you need no module for this of all tasks..#!/usr/bin/perl -w use strict; #deletes first numbytes of a file #### DO NOT USE ##### #use constant BLOCKSIZE => 128*1024; # #die "Usage: $0 numbytes file [file ...]\n" unless @ARGV > 2; # #my $trunc_bytes = shift @ARGV; #my $files_done = 0; # #for(@ARGV) { # open(my $fh, "+<", $_) or (warn "Couldn't open $_: $!\n", next); # if(-s $fh > $trunc_bytes ) { # seek $fh, 0, $trunc_bytes; # while(my $bytes_read = read $fh, my $buffer, BLOCKSIZE) { # seek $fh, 1, -$bytes_read -$trunc_bytes; # print $fh $buffer; # seek $fh, 1, $trunc_bytes; # } # } # truncate $fh, tell $fh; # close $fh; # $files_done++; #} # #exit $files_done == 0; #### DO NOT USE #####
Makeshifts last the longest.
In reply to Re: head truncate
by Aristotle
in thread head truncate
by zentara
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |