in reply to Which is better when doing a simple match?
My idea of best includes the concept of "what is the most obvious in terms of the programmer designer's intent". Now if I see a comparison operation like your first example - comparing a variable directly to a string calue withe the "eq" operator, then it is pretty clear to me - you are looking for a string equality. If you throw in some regex and other stuff, then I ask "why has the person done this - is there something deeper I haven't seen yet?". Remember the KISS principle - keep it simple, stupid.
All things being equal, always use the simplest, clearest construct - ($thing eq "thing") is understandable by almost any programmer - even visual basic people.
|
|---|