Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fwd: Error in Perlfaq6

0 views
Skip to first unread message

Meir Michanie

unread,
Aug 17, 2011, 5:56:37 AM8/17/11
to perlfaq...@perl.org
---------- Forwarded message ----------
From: Meir Michanie <meirg...@gmail.com>
Date: Wed, Aug 17, 2011 at 10:53 AM
Subject: Re: Error in Perlfaq6
To: brian...@gmail.com


 perlfaq6 - Regular Expressions ($Revision: 1.38 $, $Date: 2005/12/31
00:54:37 $)


On Wed, Aug 17, 2011 at 10:52 AM, Meir Michanie <meirg...@gmail.com> wrote:
> Hi Brian,
> The foreach loop should have the following line of code instead:
> if (/\b$pattern\b/i){print ; next LINE;}
>
> ==================================================
> How do I efficiently match many regular expressions at once?
>
>       ( contributed by brian d foy )
>
>       Avoid asking Perl to compile a regular expression every time
> you want to match it.  In this example, perl must recompile the
> regular expression
>       for every iteration of the foreach() loop since it has no way
> to know what $pattern will be.
>
>           @patterns = qw( foo bar baz );
>
>           LINE: while( <> )
>               {
>                       foreach $pattern ( @patterns )
>                               {
>                       print if /\b$pattern\b/i;
>                       next LINE;
>                               }
>                       }
> ===================================================
>

0 new messages