Another way...
#!/usr/bin/perl use strict; my %record; my $previous_event; my $max_event = 4; my $key = 1; while (my $line = <DATA>) { chomp( $line ); my ($current_event) = $line =~ /EVENT(\d)/; $record{$key}->{$current_event} = $line; $key++ if ( $current_event == 4 && $previous_event != $current_event ); $previous_event = $current_event; } for my $i (sort keys %record) { print map { $record{$i}->{$_} . "\n" } sort keys %{ $record{$i} }; } __DATA__ 09:12:50:861 EVENT1 09:13:09:467 EVENT1 09:13:09:837 EVENT1 09:13:38:059 EVENT2 09:14:03:115 EVENT3 09:14:04:076 EVENT4 09:14:11:376 EVENT1 09:14:34:049 EVENT2 09:14:34:990 EVENT3 09:14:34:990 EVENT3 09:14:34:990 EVENT4

In reply to Re: Parsing Pattern Question by bichonfrise74
in thread Parsing Pattern Question by dlcasey

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.