Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Compare two txt files and print the difference between the two files.

by trizen (Friar)
on Feb 01, 2013 at 17:06 UTC ( #1016589=note: print w/ replies, xml ) Need Help??


in reply to Compare two txt files and print the difference between the two files.

use strict; use warnings; my $first_file = shift || 'a.txt'; my $second_file = shift || 'b.txt'; open my $a_fh, '<', $first_file or die "$first_file: $!"; open my $b_fh, '<', $second_file or die "$second_file: $!"; my %second_file; @second_file{map { unpack 'A*', $_ } <$b_fh>} = (); while (<$a_fh>) { print unless exists $second_file{unpack 'A*', $_}; }


Comment on Re: Compare two txt files and print the difference between the two files.
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-09-17 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (91 votes), past polls