in reply to Re: Reading files, skipping very long lines...
in thread Reading files, skipping very long lines...
I can see one way it may work though. If there is a way to get at the indices of the newlines, you would only have to subtract the 2 to determine if the line was too long.
Cheers - L~R
Update:The following is an untested proof-of-concept.
#!/usr/bin/perl use strict; use warnings; use Tie::File; my $obj = tie my @file, 'Tie::File', 'file.big' || die "Unable to tie +'file.big': $!"; my $big = 1024 * 1024; for ( 0 .. $#file - 1 ) { my $beg = $obj->offset($_); my $end = $obj->offset($_ + 1); next if $end - $beg > $big; # process $file[$_]; } # Handle last line as special case my $beg = $obj->offset($#file); my $end = -s 'file.big'; if ( $end - $beg <= $big ) { # process $file[-1]; } #Cleanup undef $obj; untie @file;
|
|---|