in reply to Which is better when doing a simple match?

Now what do you mean by "best"? The fastest - check the benchmark results. Accurate - the match operator will match any string containing "thing" (at least as you have written it).

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.

  • Comment on Re: Which is better when doing a simple match?