Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

je44ery's scratchpad

by jffry (Hermit)
on Jul 15, 2008 at 21:17 UTC ( #697804=scratchpad: print w/replies, xml ) Need Help??

Set intersection and complement one-liners.

$ cat A; echo '* * * * *'; cat B apple cherry carrot lime * * * * * lime orange banana

A ∩ B
Intersection of A and B.

$ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; f +or (<F>) {print if $set{$_}};' A B lime

B / A
Complement of B relative to A.

$ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; f +or (<F>) {print unless $set{$_}};' A B apple cherry carrot

The first argument is always set A. The union of all the other arguments is set B. Thus:

$ cat C grape apricot cherry $ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; f +or (<F>) {print unless $set{$_}};' A B C apple carrot $ perl -e 'open F,$ARGV[0] or die;shift;my %set = map {$_ => 1 } <>; f +or (<F>) {print if $set{$_}};' A B C cherry lime
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the questions are moot...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2016-12-10 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (163 votes). Check out past polls.