in reply to Removing the first record in a file containing fixed records

I know this will work on Linux but I'm pretty sure that it won't work on Windows:

my $filename = 'somefile'; my $rec_len = 567; open my $IN, '<:raw', $filename or die "Cannot open '$filename' $!"; open my $OUT, '+<:raw', $filename or die "Cannot open '$filename' $!"; my $file_size = -s $IN; my $total_records = $file_size / $rec_len; $/ = \$rec_len; while ( <$IN> ) { next if $. == 1; print $OUT $_; } $total_records == $. or die "Read only $. records but expected $total_ +records records!\n"; truncate $IN, $file_size - $rec_len; close $OUT; close $IN;

Or you could do it using one of the memory mapped file modules which should work on windows.

Replies are listed 'Best First'.
Re^2: Removing the first record in a file containing fixed records
by Corion (Patriarch) on Jul 18, 2008 at 06:11 UTC

    What makes you so sure it won't work on Windows?

    The :raw IO layer is equivalent to the binmode and I see no unixisms in your code that would prevent the program from working on Windows.

    I just saw - you're opening the same file twice. This won't work under Windows - you'll have to seek back and forth in the one file to copy the data from the end to the front.

    Update2: I tested your code on Win32 and it just works.

      I don't use Windows so I have no way to verify if it does or does not work there, sorry.