Hello rahu_6697,

I'm not sure I've understood your question, but time will tell..

First of all I think you need some advice on syntax: in order of importance @arr & @arr2

perl -E "@a1=qw(1 2 3); @a2=qw(a b c d e); say for (@a1 & @a2)" 1 perl -E "@a1=qw(1 2 3); @a2=qw(a b c d e); say for (@a1 , @a2)" 1 2 3 a b c d e

Infact to concatenate two list in list context the comma is used not & see perlop

Then your way to open filehandle, while running, is oldish and error prone:

open(FILE, "<x.log"); close (FILE); # has to be open my $file_handle, '<', 'x.log' or die "unable to open 'x.log' $!"; .. close $file_handle;

Third, you are reassigning twice to @array2 = grep .. and, as long as you print to the destination file immediately, can also be what your intended, but is not clear and error prone in long distance: grep in list context will returns a list and you can use push to extend the array:

my @array; ... #push 1 push @array, $_ for grep{.. #push 2 push @array, $_ for grep{..

Also please use  <code> ..code tags.. </code> also for your data input/output

PS After reading twice, please clearify the following:

> Now I want to compare the data present after the keyword following colon(:) and in output file I have to print the mismatched lines from first data-set on comparing it with second data-set and number of lines in second data set that are not present in first data-set.

If I understand what you are asking for I'd go with a datastructure like a hash of arrays, which keys will be all keywords occurences and array element populed by the evntual presence in file 1 and file 2:

# pseudocode my %report; foreach my $line( $fh_one ){ if... matching.. extract the part interesting $report{ $interesting_part }[0] = 1; # first file populates the +element 0 foreach my $line( $fh_two ){ if... matching.. extract the part interesting $report{ $interesting_part }[1] = 1; # first file populates the +element 1 # result like %report = ( interesting1 = [ undef, 1 ], # is present only in the second file interesting2 = [ 1, undef ], # is present only in the first file interesting3 = [ 1, 1 ], # is present in both files );

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Compare two log files line by line containing a keyword by Discipulus
in thread Compare two log files line by line containing a keyword by rahu_6697

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.