in reply to head truncate
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: head truncate
by sauoq (Abbot) on Sep 13, 2002 at 01:00 UTC | |
by Aristotle (Chancellor) on Sep 13, 2002 at 13:26 UTC | |
by sauoq (Abbot) on Sep 13, 2002 at 20:03 UTC | |
by Aristotle (Chancellor) on Sep 13, 2002 at 21:18 UTC | |
by sauoq (Abbot) on Sep 14, 2002 at 00:35 UTC |