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

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.