Untested, but no glaring mistakes obvious to me. If you see any, yell at me. Update: turns out there are rather serious ones. Do not use this code. Left here for posterity.
#!/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 #####
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..

Makeshifts last the longest.


In reply to Re: head truncate by Aristotle
in thread head truncate by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.