[lug] parsing between two lists

qqq1one @yahoo.com qqq1one at yahoo.com
Wed Mar 27 23:11:33 MST 2002


I'm not much of a perl composer (yet).  Could you check my
understanding of how this script works?

The first while loop builds an internal list of everything that is in
file_a.txt.  Then the second while loop deletes everything from the
list if it is also found in file_b.txt, no?

Getting this script to list everything in file_b.txt that is not in
file_a.txt can be accomplished just by swapping the file names.

But how would you get it to list everything that is common to both
files?  Can you just add some sort of "NOT" to the second while loop to
accomplish this?

--- Rob Nagler <nagler at bivio.biz> wrote:
> > ...but I would rather have a list that shows what's in fileA that's
> not
> > in fileB:
> 
> I just had this problem yesterday.  Here is a very quick hack:
> 
> #!/usr/bin/perl -w
> my($FILE_A) = {};
> open(IN, 'file_a.txt') || die("open 'file_a.txt': $!");
> while (<IN>) {
>     chomp;
>     next unless $_;
>     $FILE_A->{lc($_)}++;
> }
> close(IN) || die;
> 
> open(IN, 'file_b.txt') || die("open 'file_b.txt': $!");
> while (<IN>) {
>     chomp;
>     next unless $_;
>     delete($FILE_A->{lc($_)});
> }
> print join("
", sort(keys(%$FILE_A))), "
";
> 
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug



__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/



More information about the LUG mailing list