i am trying to process a largish ~50 mb log file ,however with the current code ,its taking way too long

i am basically searching for unique id's in second [] and then looping thru whole file looking for keywords and writing to output file..but its taking hours

my@id; my $date; my $id; my $keyword; my $mess; my @uniqueid; my %seen; #read the file (PLEASE PROVIDE INPUT FILE PATH) open(hanr,"d:/Log.txt")or die"error $!\n"; #digesting the lines @lines = <hanr>; #iterating through the lines foreach $line (@lines) { $line =~ /\[(.+?)\] .* \[(.+?)\] .* \[[^]]+\] \s+ (.*) /x or next +; $id = $2; push (@id , $id); #pushing id to array } #for getting unique user id's foreach $value (@id) { if (! $seen{$value}++ ) { push @uniqueid, $value; } } #OPENING OUTPUT FILE;PROVIDE PATH open (myfile,">D:\\output\\op.txt") or die("error:cannot create $! \n" +); foreach $uniquevalue (@uniqueid) { foreach $line (@lines) { $line =~ /\[(.+?)\] .* \[(.+?)\] .* \[[^]]+\] \s+ (.*) /x or n +ext ; $date = $1; $id = $2; $keyword = $3; if($uniquevalue eq $2 && $keyword eq "Orchestration Started"){ print myfile "$date,$id,$keyword \n"; next; } if($uniquevalue eq $2 && $keyword =~/^Input Message/){ print myfile "$date,$id,"."Input Message to P5 \n"; next; } if($uniquevalue eq $2 && $keyword =~ /^TP Service Request/){ print myfile "$date,$id,"."Service Request \n"; next; } if($uniquevalue eq $2 && $keyword =~/^P5 Move request :/ ){ print myfile "$date,$id,"."Move request \n"; next; } if($uniquevalue eq $2 && $keyword =~/^ProcessName:/){ $mess = substr $keyword , 12; print myfile "$date,$id,$mess \n"; next; } if($uniquevalue eq $2 && $keyword =~/^Process Message :/ ){ my $mess = substr $keyword , 17; print myfile "$date,$id,$mess \n"; next; } } }

the search for unique id's is fast enough , but for the second block ,the if loops are searching for keyword for each unique id thru the WHOLE file.its painfully slow,how can i improve speed ??

ps. as requested a sample of log or exact signature

[2014-06-24 15:10:10,936] DEBUG - [27421b9e-fbd3-11e3-943c-ff89c266c130] [PreProcess] Ended successfully.

[2014-06-24 15:10:10,936] DEBUG - [27421b9e-fbd3-11e3-943c-ff89c266c130] [PreProcess] Orchestration Started

[date]text - [uniqueid][sometext]keyword-egProcessName:

also this is some more information , i dont need the id's in order in output file. and for each unique id like 27421b9e-fbd3-11e3-943c-ff89c266c130 i want to log date , id and "keyword" so i will pickup only the second line above


In reply to 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.