Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://198666]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2023-02-08 07:50 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (40 votes). Check out past polls.