Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Style question: regex versus string builtin function

by thospel (Hermit)
on Oct 02, 2007 at 11:33 UTC ( [id://642075]=note: print w/replies, xml ) Need Help??


in reply to Style question: regex versus string builtin function

I'd definitely go for the regex. If I later would read that code, I'd have to think for half a second about the index code to see that's it's not a "where is this needle", but that it's a "does the needle exist anywhere", while a regex immediately gives that kind of association. If index is faster, that is an implementation detail. If we care, we should just fix the perl optimization code to make them equivalent. But by default clarity not speed is the goal of writing code.
  • Comment on Re: Style question: regex versus string builtin function

Replies are listed 'Best First'.
Re^2: Style question: regex versus string builtin function
by rir (Vicar) on Oct 02, 2007 at 15:02 UTC
    that it's a "does the needle exist anywhere", while a regex immediately gives that kind of association

    g, that doesn't work for me.

    Regexes are inherently more complex to use than the index function. There are the various regular expression dialects, there are the modifiers, and there are the global variables upon which they may trample.

    But, like others, I tend to reach for the match operator.

    Be well,
    rir

Log In?
Username:
Password:

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

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

    No recent polls found