(Pretty much what RonW said.) You require fast lookup over the $id field. Populate your data structure accordingly! Hash will be a good choice here.

If I understood correctly, the task is about grouping lines in a log file by the ID field, plus some additional munging. The following skeleton code might give you some ideas:

use strict; use warnings; # @ID to keep unique id's (in order they are seen) # %T to group things by id. Make it HoA (Hash of Arrays) my (@ID, %T); ... while (<HANR>) { my ($date, $id, $kw) = /\[(.+?)\]/g; my $txt; next unless $kw; $txt = "$+ to P5" if $kw =~ /^(Input Message)/; $txt = $+ if $kw =~ /^(Orchestration Started)$/; $txt = $+ if $kw =~ /^ProcessName:(.*)/; # note the opportunity to merge some regexes above next unless $txt; push @ID, $id unless $T{$id}; push @{ $T{$id} }, "$date,$id,$txt \n"; } for my $group (@T{ @ID }) { # this is a hash slice! print OUT for @$group; }
ps. I'm trying to puzzle out what hanr might stand for? And what is a displamer?

Update.

In above example, the @ID array is only to keep IDs ordered by their first encounter. If that's unimportant, replace the hash slice with just (values %T). The $+ is documented in perlvar. But my regex to split fields doesn't quite cut it if kw is not in brackets - needs a fix.

Having a firm handle on (perl) data structures is of great utility; it helps one in making the right algorithmic decisions. For starters, perldsc is a good read.

pps. I'm awfully suspecting that Hanr shot first. With a displamer.

In reply to Re: very slow processing by oiskuu
in thread very slow processing by sandy105

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.