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

Re: [FWP] words words words



On Fri, May 19, 2000 at 11:13:31AM -0400, Ala Qumsieh wrote:
> Here's my shot at it. I didn't benchmark, though. But, if you do, then
> please let me know:
> 
> 	open T, "threes" or die $!;
> 	chomp(my @three = <T>);
> 	my %three;
> 	@three{@three} = ();
> 	close T;
> 
> 	open N, "nines" or die $!;
> 	while (<N>) {
> 	    exists $three{$1} && exists $three{$2} && exists $three{$3} &&
> 	        print if /(...)(...)(...)/;
> 	}

This one is very similar to Tim's, but ends up twice as fast, probably
because it avoids grep and m//g.  Nice work.


> And here's a compact version of the same program:
> 
> 	@ARGV="threes";
> 	chomp and$three{$_} = 1 for<>;
> 	@ARGV="nines";
> 	/(...)(...)(...)/&&exists$three{$1}&&
> 	                   exists$three{$2}&&
> 	                   exists$three{$3}&&
> 	                   print 
> 		for<>;
> 
> (which is actually just 4 lines long)

You don't need the exists in that one, since you're setting the values in
the hash to 1.

Ronald

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