Happy-the-monk,
I do not believe either one of these approaches will work (if I understand the problem correctly). Some lines are too long to read into a single variable so it is not possible to use length to determine if a line is too long. Using
Tie::File would help since it only indexes where the newlines in the file begin, but you still need to read the whole line to determine if it is too long (
length $file[42] > 1024 * 1024).
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.
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;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.