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

Re: [MacPerl] RFC: How can I optimise bulk matching regex



Quoting robinmcf@altern.org:

> I'm currently working on a dictionary project, I'm using -
> @searchterms= qw (
> 	term1
> 	term2
> 	term3
> 	...);
> 
> while (<>) {
>     foreach $item(@searchterms) {
> 	if (/$item\/go) {
> 	    do stuff....;
> 	}
>     }
> }
> 
You basically want to find out if a word you encounter is in a list. So
use a hash, with the keys being the searchterms. Then just use 'exists'.

The values of the hash can be relevant or irrelevant, depending on the
nature of "do stuff...".

Arved


---------------------------------------------------------------
 This mail was sent through the Nova Scotia Provincial Server.
 http://nsaccess.ns.ca/mail/ (in development)

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org