What was your attempt with read() ? It takes a length to read, so you can read chunks at a time .. but i think you have to handle the line breaks yourself ...

Update: I started an attempt with read(), but hit a snag .. i think i need to restart my attempt and read 1 char at a time..
use strict; use warnings; use Data::Dumper; use constant MAX_LINE_LENGTH => 25; my $file = '/etc/hosts'; my @lines; my $prev_line = ''; while( !eof DATA ){ my $line; read DATA, $line, MAX_LINE_LENGTH; push @lines, $line; } print Dumper \@lines; __DATA__ this is a line aqwewqe short shrt short2 short3 this is a line asdas this is a another very ling line lkjkdsa to skip qweqweqwewqewqewqeqwe this is a line asdasd this is a line lkjqwe this is a very ling line lkjkdsa to skip qweqweqwewqewqewqeqwe this is a line ad as


Update2: Not overly impressive coding, but i think this works (i created a long ~7.8M line with for f in `seq 1 1000000` ; do echo -n "blahblahblah" >> /tmp/longline ; done in bash and stuck it in the DATA section and it seemed to work):
use strict; use warnings; use Data::Dumper; use constant MAX_LINE_LENGTH => 25; my $file = '/etc/hosts'; my @lines; my $line = ''; while( !eof DATA ){ my $c; read DATA, $c, 1; if( length($line) > MAX_LINE_LENGTH ){ $line = '' if $c eq "\n"; next; } if( $c eq "\n" ){ push @lines, $line; $line = ''; next; } $line .= $c; } print Dumper \@lines; __DATA__ this is a line aqwewqe short shrt short2 short3 this is a line asdas this is a another very ling line lkjkdsa to skip qweqweqwewqewqewqeqwe this is a line asdasd this is a line lkjqwe this is a very ling line lkjkdsa to skip qweqweqwewqewqewqeqwe this is a line ad as

In reply to Re: Reading files, skipping very long lines... by davidrw
in thread Reading files, skipping very long lines... by Excalibor

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.