Hi Mike, On Tue, 13 May 2014 02:36:30 -0500 Mike Dunaway <ekimduna...@gmail.com> wrote:
> Hello everyone. Let's say I have a user provide @list of words and I > want to match each words against a file or a another @list of words and > increase a counter every time a word in the given list appears in what > I'm matching against, what might a possible solution look like for that? > The only thing I could think of is a nasty mess of a ton of for loops > restarted until you get to the end of the user provided list which may > end up being very slow depending on the size of the list. What if I > wanted to also use regular expressions? > It sounds like what you want is a hash: http://perl-begin.org/topics/hashes/ (NOTE: perl-begin.org is my domain). Untested code: < CODE > use strict; use warnings; my @words_to_look_for = ( ... ); my %words_lookup = (map { $_ => 1 } @words_to_look_for); my $counter = 0; foreach my $word (@list_of_words_to_search) { if (exists $words_lookup{$word}) { $counter++; } } < / CODE > Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Why I Love Perl - http://shlom.in/joy-of-perl “Publish or Perish” → “Life or Death” — http://unarmed.shlomifish.org/2615.html Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/