in reply to Reading files, skipping very long lines...
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
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
|
|---|