Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi!

Look at this. Probably it helps to find the way.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $filename1 = 'file1.txt'; my $filename2 = 'file2.txt'; open my $fhin1, "<", $filename1 or die "ERROR: Can't open file '$filen +ame1': $!"; open my $fhin2, "<", $filename2 or die "ERROR: Can't open file '$filen +ame2': $!"; my %lines_found_in_file1 = map { chomp; s/^\s+//; s/\s+$//; $_ => 1 } (<$fhin1>); my %lines_found_in_file2 = map { chomp; s/^\s+//; s/\s+$//; $_ => 1 } (<$fhin2>); close $fhin1 or die "ERROR: Couldn't close file '$filename1': $!"; close $fhin2 or die "ERROR: Couldn't close file '$filename2': $!"; my $output1 = 'common.txt'; my $output2 = 'uncommon.txt'; open my $fhout1, ">", $output1 or die "ERROR: Can't open file '$output +1': $!"; open my $fhout2, ">", $output2 or die "ERROR: Can't open file '$output +2': $!"; # Compare in one direction foreach my $line (keys %lines_found_in_file1) { if(exists $lines_found_in_file2{$line}) { print $fhout1 $line, "\n"; } else { print $fhout2 $line, "\n"; } } # Compare in other direction foreach my $line (keys %lines_found_in_file2) { if(exists $lines_found_in_file1{$line}) { # Don't do anything as you printed these lines in the first go } else { print $fhout2 $line, "\n"; } } close $fhout1 or die "ERROR: Couldn't close file '$output1': $!"; close $fhout2 or die "ERROR: Couldn't close file '$output2': $!";

Best regards
McA


In reply to Re: Need help for extracting Log file using Perl script by McA
in thread Need help for extracting Log file using Perl script by renjoooz

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (9)
    As of 2014-07-24 08:28 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (158 votes), past polls