All pastes #407527 Raw Edit

Untitled

public text v1 · immutable
#407527 ·published 2007-03-24 02:42 UTC
rendered paste body
#!/usr/bin/env perl 

while (<>) {
    m/\s[A-Z]+\s+\[([^\]]+)\]\s/ || next;
    $thread = $1;

    if (m/\scollection failed for\s(\S+)/) {
        $ip = $1;

        printLastForThread($thread, $_);
    } else {
        pushThread($thread, $_);
    }
}

sub printLastForThread {
    my $thread = shift(@_);
    my $line = shift(@_);

    if (exists($thread{$thread})) {
        print(@{$thread{$thread}});
    }

    print($line);
    print("\n");
}

sub pushThread {
    my $thread = shift(@_);
    my $line = shift(@_);

    if (exists($thread{$thread})) {
        $size = scalar(@{$thread{$thread}});
        if ($size > 4) {
            splice(@{$thread{$thread}}, 0, $size - 4);
        }
    }

    push(@{$thread{$thread}}, $line);
}