Is there a way to precompile regular expressions?
I have an array of acceptable matches, and an array of items to grep from.
I want to avoid recompiling the regular expression over and over again, for
each loop.
ie. (imagine these lists are much longer).
@stuff = (
"Micheal",
"Marko",
"Marcy",
"Rebecca",
"Bob",
"Jancy",
"Jill",
"Jamie",
"Jack",
);
@accept = qw( Ja Ma );
my @goodstuff;
foreach my $item (@stuff){
foreach my $accept (@accept){
push @goodstuff, $accept if $item =~ /$accept/; ## my
problem is this might take long recompiling each time
}
}
print "@goodstuff\n";
__END__
# alternative is:
foreach my $accept (@accept){
push @goodstuff, grep /$accept/, @stuff;
}
# but this isn't better because in my script @accept is much bigger/longer
than @stuff
Nikola Janceski
Here it is my time,
Where there are no crimes,
Only I exist here,
And have no fear.
-- Riddles
----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]