Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: Character class in an array

by Fastolfe (Vicar)
on Sep 17, 2002 at 22:05 UTC ( #198666=note: print w/replies, xml ) Need Help??


in reply to Re: Character class in an array
in thread Character class in an array

You're repeating that interpolation on every trip through the loop, when you could be using qr// to compile your regex once and then forget about it.

The /o flag on the regex will also work without requiring him to create a regex scalar with qr//.

Replies are listed 'Best First'.
Re: Re: Re: Character class in an array
by PodMaster (Abbot) on Sep 18, 2002 at 02:50 UTC
    And it may not work always. See 'o' modifier clarification needed

    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      The original poster had a constant array and the post I was responding to was discussing the benefits of optimizing queries for "once-only" compilation. Obviously if you are wanting to change the array between pattern matches, you'll want to ensure your pattern is current.

      Sorry, misreplied.

Re^3: Character class in an array
by Aristotle (Chancellor) on Sep 17, 2002 at 22:08 UTC
    But will fail if the regex is used multiple times with varying array contents.

    Makeshifts last the longest.

      I was just extending the original poster's qr/// suggestion. If you interpolate a variable in a 'qr' string, it "stays" interpolated and will not change if the value of the original variable changes with it, unless you re-create the string for every iteration. Obviously, if you're going to want to use qr/// or the /o flag on a regex, you are doing so because you wish Perl to compile the regular expression once (at least within the lexical scope of the qr/// string).
        True enough - what I'm saying is you don't have that option to begin with when using /o.

        Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://198666]
help
Chatterbox?
LanX hates UTF8 for causing knots in his brain and stomach
[Corion]: LanX: Yes, that's the main problem - you have lots (and lots) of workarounds in various places and stages of the processing, and to clean that mess up requires action across the complete codebase. And it's almost impossible to do it piece-by-piece

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2017-01-16 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (150 votes). Check out past polls.