Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: compare two text files

by Samy_rio (Vicar)
on Jul 14, 2005 at 05:16 UTC ( #474752=note: print w/replies, xml ) Need Help??


in reply to compare two text files

Hi,

use List::Compare; use strict; open (F, "a.txt")||die("a.txt File cannot open\n"); open (S, "b.txt")||die("b.txt File cannot open\n"); my @a=<F>; my @b=<S>; my $lcma = List::Compare->new(\@a, \@b); print $lcma->get_complement ,"\n"; # extra present in the second array + print $lcma->get_unique ,"\n"; # extra present in the First array

I think it helps you.

Regards,
Velusamy R.

Replies are listed 'Best First'.
Re^2: compare two text files
by juergenkemeter (Novice) on Jul 14, 2005 at 05:39 UTC
    Hi! It all works fine, thank you. Next time I will post my "trying code" with my thread. In case of homework: I ordered the book "Learning Perl" today. One last question occured to me though: is there a way to put the output into a new textfile? Thanks a lot for your fast help, Jurgen

      Hi,

      open(OUT, ">new.txt")||die("cannot create\n"); print OUT "\nExtra Text present in the second File\n", $lcma->get_comp +lement ,"\n"; print OUT "\nExtra Text present in the First File\n", $lcma->get_uniqu +e ,"\n";

      You just replace the last two line of my code with the above code.

      Regards,
      Velusamy R.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474752]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2023-01-30 17:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?