Contrast Tie::File taking 233 seconds:

use strict; use warnings; use Tie::File; $/ = \96; my $start = time; tie my @records, 'Tie::File', $ARGV[ 0 ]; shift @records; untie @records; printf "Time: %f seconds\n", time() - $start; __END__ 2008-07-18 14:17 527,999,712 500MB.fixed 1 File(s) 527,999,712 bytes 0 Dir(s) 2,320,445,440 bytes free C:\test>junk7 500MB.fixed Time: 233.000000 seconds C:\test>dir 500MB.fixed Volume in drive C has no label. Volume Serial Number is BCCA-B4CC Directory of C:\test 2008-07-18 23:34 527,999,616 500MB.fixed 1 File(s) 527,999,616 bytes 0 Dir(s) 2,320,416,768 bytes free

With a read-seek-write solution taking < 5 seconds:

#! perl -slw use strict; use Fcntl qw[ SEEK_CUR SEEK_SET ]; use constant BUFSIZE => 64 * 1024; my $start = time; our $RECLEN || die "you must specify the length of the header. -RECLEN +=nnn"; @ARGV or die "No filename"; open FILE, '+<:raw', $ARGV[ 0 ] or die "$!: $ARGV[ 0 ]"; sysread FILE, my $header, $RECLEN or die "sysread: $!"; my( $nextWrite, $nextRead ) = 0; while( sysread FILE, my $buffer, BUFSIZE ) { $nextRead = sysseek FILE, 0, SEEK_CUR or die "Seek query next read failed; $!"; sysseek FILE, $nextWrite, SEEK_SET or die "Seek next write failed: $!"; syswrite FILE, $buffer or die "Write failed: $!";; $nextWrite = sysseek FILE, 0, SEEK_CUR or die "Seek query next write failed $!"; sysseek FILE, $nextRead, SEEK_SET or die "Seek next Read failed: $!"; } truncate FILE, $nextWrite or die "truncate failed: $!"; close FILE or die "close failed: $!"; printf "Took: %f seconds\n", time() - $start; __END__ C:\test>dir 500MB.fixed Volume in drive C has no label. Volume Serial Number is BCCA-B4CC Directory of C:\test 2008-07-18 23:34 527,999,616 500MB.fixed 1 File(s) 527,999,616 bytes 0 Dir(s) 2,320,416,768 bytes free C:\test>698472 -RECLEN=96 500MB.fixed Took: 5.000000 seconds C:\test>dir 500MB.fixed Volume in drive C has no label. Volume Serial Number is BCCA-B4CC Directory of C:\test 2008-07-18 23:37 527,999,520 500MB.fixed 1 File(s) 527,999,520 bytes 0 Dir(s) 2,320,445,440 bytes free

I'll grant you, it does have the virtue of simplicity.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^4: Removing the first record in a file containing fixed records by BrowserUk
in thread Removing the first record in a file containing fixed records by sparkle

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.