Hi Monks, I need suggestions on the fastest way to do this: I have 3 directories with log files in them. All log files have the following pattern.

< block>

< id> xyz < /id>

< url> foo.com < /url>

..

< response> xyz < /response>

< /block>

< block>

..

The task is to get the id if the url is foo.com from logs of first directory , search for that id in all the directories(including first one) print the responses from the corresponding blocks into a saparate file.
#getting the ids from first directory sub doFile($) { my ($fn) =@_; chomp($fn); print "opening $fn\n"; my $fh = IO::File->new($fn, 'r'); my @msgLines; if( defined $fh){ while(my $l = <$fh>) { push @msgLines, $l; if($l =~ m"</msg>\s*\$") { #my $msg = join('', @msgLines); my $id; if(grep{ m"http://.*foo.com" } @msgLines) { #store the @msglines into an array, this + array can serve as source for searching for reponses from first dire +ctory, need to do something similar for the rest of directories. $id = grep { $_ =~ m"<Id>(\d+)</Id>"; +} #@msgLines; # $id =~ m"<Id>(\d+)</Id>"; push @IDs, $id; } @msgLines = (); } } } else{ die "Cannot open file $!\n";} } my @firstdir=@{$logfiles[0]}; my $path=$logdirs[0]; foreach (@firstdir) { my $curpath=sprintf($path.'/'.$_); print"In foreach trying to open $path\n"; doFile($curpath); }
The log files are huge, so zipping them into a single file is not possible(out of disk space). Any perl modules that can help me with this task?

In reply to Best way to search through blocks of data by baski
in thread Searching a gzip file by baski

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.