[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Wanted - Have = Need



On Fri, Oct 13, 2000 at 10:51:33AM -0400, Kevin Hemenway wrote:
> At 09:46 AM 10/13/00, Ronald J Kimball wrote:
>  >On Fri, Oct 13, 2000 at 09:34:51AM -0400, Keith Calvert Ivey wrote:
>  >> Jeff Pinyan <jeffp@crusoe.net> wrote:
>  >>
>  >> > perl -e 'do{$w{<>}=1}until+eof;delete@w{<>};print+keys%w' WANT HAVE
>  >>
>  >>   perl -e "@w{<>}=();@ARGV=HAVE;delete@w{<>};print+keys%w" WANT
>  >
>  >    perl -e '@w{<>}=();@ARGV=HAVE;delete@w{<>};print%w' WANT
>  >
>  >:)
> 
> Heh... Gotta love it. What does it mean? I have no freakin' clue...
> 

Basically, we're using a hash to do set operations.  The keys of a hash are
unique and unordered, just like a set.

do { $w{<>} = 1 } until eof  and  @w{<>} = ()  populate the set with the
contents of the first file.

delete @w{<>}  subtracts from the set the contents of the second file.

print keys %w  and  print %w  print the elements of the set.  print %w
works because in that code all the values of the hash are undef, so they
get printed as empty strings in between the keys.


Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe