I know that, but I want it to change each time, but I was wondering if I can compile the regular expression before using it, since it's the same REs each time through the outer loop.
I want it to test for either of the items in @accept (which is bigger in my program), but I don't want to waste time compiling the samething over and over again. > -----Original Message----- > From: Wagner-David [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 21, 2002 2:07 PM > To: 'Nikola Janceski'; Beginners (E-mail) > Subject: RE: precompile regular expressions? > > > As part of regex use o like /$accept/o and this should > compile only once vs each time through. Don't have all my > books with me, but believe this will do it. > > Wags ;) > > -----Original Message----- > From: Nikola Janceski [mailto:[EMAIL PROTECTED]] > Sent: Thursday, March 21, 2002 10:50 > To: Beginners (E-mail) > Subject: precompile regular expressions? > > > 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] > ---------------------------------------------------------------------------- -------------------- 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]