Deus Ex has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I've looked through the documentation and the internet, but found no answer so far, so here is my question.
I've got an array, say (a, b, c, d), and i've got a file, which contain lines which will on won't match with one of the array elements.
So, I'm looking for a shorter and more efficient way to match the lines with the array elements than a foreach() (or a for() for what that matters), like
my @array = qw(a b c d); open(my $file, myfile.txt); while (<$file>) { if ($_ =~ $array[0..$#array]) { ## instead of: foreach(@array) print "Matches!\n"; } }
As i already tested by myself, the match part won't work, so any help will be appreciated (if there's of course a solution, otherwise i'll surrend and use a foreach().
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex and array
by Corion (Patriarch) on May 25, 2010 at 10:11 UTC | |
by Deus Ex (Scribe) on May 25, 2010 at 12:34 UTC | |
by toolic (Bishop) on May 25, 2010 at 12:47 UTC | |
by Deus Ex (Scribe) on May 25, 2010 at 13:07 UTC | |
by Corion (Patriarch) on May 25, 2010 at 12:41 UTC | |
by Deus Ex (Scribe) on May 25, 2010 at 12:56 UTC | |
by vtheron (Novice) on May 25, 2010 at 21:38 UTC | |
by Deus Ex (Scribe) on May 26, 2010 at 09:50 UTC | |
|
Re: Regex and array
by baxy77bax (Deacon) on May 25, 2010 at 10:52 UTC | |
by toolic (Bishop) on May 25, 2010 at 13:30 UTC | |
by Deus Ex (Scribe) on May 25, 2010 at 13:11 UTC |