Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: How to find the difference between two text files using a hash array

by Kenosis (Priest)
on Jan 20, 2013 at 21:33 UTC ( #1014341=note: print w/ replies, xml ) Need Help??


in reply to How to find the difference between two text files using a hash array

Consider using List::Compare to compare the two arrays. Below is an example of its use. The results show items that appear only in the left list contained by @array1:

use strict; use warnings; use List::Compare; my @array1 = split /\n/, <<END1; /home filer1232:/vol/home1 /mystuff filer1233:/vol/project /data filer1234:/vol/example_data /software filer1255:/vol/my_software /tools filer1235:/vol/my_tools /docs filer146:/vol/my_documents END1 my @array2 = split /\n/, <<END2; /home filer1232:/vol/home1 /mystuff filer1233:/vol/project /data filer1234:/vol/example_data /tools filer1235:/vol/my_tools END2 my $lc = List::Compare->new( \@array1, \@array2 ); my @Lonly = $lc->get_unique; print "$_\n" for @Lonly;

Output:

/docs filer146:/vol/my_documents /software filer1255:/vol/my_software


Comment on Re: How to find the difference between two text files using a hash array
Select or Download Code
Re^2: How to find the difference between two text files using a hash array
by NewLondonPerl1 (Acolyte) on Jan 20, 2013 at 21:39 UTC
    Thanks alot everyone for your help. I will try this out now
Re^2: How to find the difference between two text files using a hash array
by NewLondonPerl1 (Acolyte) on Jan 20, 2013 at 21:48 UTC
    Ok I have tried using List::Compare and unfortunately we dont have this perl module. I am going to try out these other suggestions now

      Below generates the same results w/o using the module:

      use strict; use warnings; my @array1 = split /\n/, <<END1; /home filer1232:/vol/home1 /mystuff filer1233:/vol/project /data filer1234:/vol/example_data /software filer1255:/vol/my_software /tools filer1235:/vol/my_tools /docs filer146:/vol/my_documents END1 my @array2 = split /\n/, <<END2; /home filer1232:/vol/home1 /mystuff filer1233:/vol/project /data filer1234:/vol/example_data /tools filer1235:/vol/my_tools END2 my %currMounted = map { $_ => 1 } @array2; print "$_\n" for grep !$currMounted{$_}, @array1;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-09-01 19:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls