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 | |
by jwkrahn (Abbot) on Jul 18, 2008 at 07:54 UTC |