[lug] parsing between two lists

Rob Nagler nagler at bivio.biz
Thu Mar 28 08:10:14 MST 2002


> 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?

correct.

> 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.

yes.

> 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?

What you want is an affirmation.

> >     delete($FILE_A->{lc($_)});

Doing the simplest thing that could possibly work, I would change the
above line to:

$FILE_A->{lc($_)}++;

and then:

print join("\n", sort(grep($FILE_A->{$_} == 2, keys(%$FILE_A)))), "\n";

I'm sure there are more clever ways to do this.  Personally I
appreciated the pipeline approach.  I'm just kind of a Perl guy and
use it in place of pipelines for a variety of reasons.

Rob







More information about the LUG mailing list