Have you considered fixing the underlying problem: the bug limiting the size of your buf? Here's a solution if you can't.
If you remove the newlines, then you can just search for very long terms and replace them.
use strict; use warnings; my $file = '...'; open(my $fh, '<', $file) or die("Unable to open file \"$file\": $!\n"); my $reader = Reader->new($fh); while (defined(my $line = $reader->get_line())) { $line =~ s/\S{40,}/.../g; print($line); }
{ package Reader; sub new { my ($class, $fh) = @_; my $self = bless([$fh, undef]); } sub get_line { my ($self) = @_; our $fh; local *fh = \($self->[0]); our $buf; local *buf = \($self->[1]); if (!defined($fh)) { return undef; } if (!defined($buf)) { for (;;) { my $line = <$fh>; if (!defined($line)) { undef $fh; return undef; } if ($line =~ /^\d\d:\d\d:\d\d /) { $buf = $line; last; } } } for (;;) { my $line = <$fh>; if (!defined($line)) { undef $fh; return "$buf\n"; } if ($line =~ /^\d\d:\d\d:\d\d /) { return ((undef, $buf) = ($buf, $line))[0]; } chomp($buf); $buf .= $line; } } }
Output:
09:59:58 09/28/07 1 192.168.0.7 1.3.6.1.2.1.1.3.0 TimeTick 335604562 1 +.3.6.1.6.3.1.1.4.1.0 OID 1.3.6.1.4.1.9.9.383.0.1 1.3.6.1.4.1.9.9.383. +1.1.1 Counter64 1119125906 1.3.6.1.4.1.9.9.383.1.1.2 String 07d7091c0 +9361400 1.3.6.1.4.1.9.9.383.1.2.14 String ... 1.3.6.1.4.1.9.9 String +... 1.3.6.1.4.1.9.9.383.1.2.16 String 192.168.20.60:3089 1.3.6.1.4.1. +9.9.383.1.2.17 String osIdSource="unknown" osRelevance="relevant" osT +ype="unknown" 192.168.0.23:139
In reply to Re: text parsing question
by ikegami
in thread text parsing question
by perlAffen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |