Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Character class in an array

by Fastolfe (Vicar)
on Sep 17, 2002 at 22:05 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://198666]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-04-18 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found