Thanks, I'll look into this and give it a try.

On 05/13/2014 03:08 AM, Shlomi Fish wrote:
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



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to