Re: searching for a special string in an array



Shai wrote:
I'm running on an array of strings with a foreach loop.
I want to stop the loop when I find the string: "item(s)" - but it
looks like I have problems with defining the if condition.
I tried:
if ($str=~"item(s)") {

It would be less confusing to you and others if you used the customary /.../
for REs.
Double quotes are a particularly poor choice because naturally people will
confuse the text with a string.

last;
}
But it seems to have problems. if I remove the "(s)" it works fine but

You need to escape the parantheses because they are using for grouping in
REs.

I need to find a unique string which contains exactly this: "item(s)".
Any idea ?!?!?

Even better: use the right tool. If you want to search for a substring
within another string then index() is your friend. No need to wield the big
RE cannon for that task.

jue


.



Relevant Pages

  • Re: Whats so special about operators, built-in classes and modules?
    ... will prevent people from modifiying string. ... Aside from the issue of C strings, I'd say the way const is used in functions is b0rken in C. Take int foo; Since bar is passed by value, any modifications of it in the body of the function are only local to the function. ... And the syntax for that is really confusing -- generally the syntax for pointers is really confusing in C as a general rule. ... As for multiple inheritance vs. single inheritance, I think the problem isn't a technical one, it's a human one. ...
    (comp.lang.ruby)
  • Re: Function shortcut help
    ... Helmut, and Tony: ... Sorry for the confusing post, ... Public Function MyResult(x As String, ...
    (microsoft.public.word.vba.general)
  • Re: My fight with classes :)
    ... I got started to try a concatenation of 2 type of string, ... It was confusing to design your class in such a way that "k+'aks'" ...
    (comp.lang.python)
  • Re: Predicting the Future and Kolmogorov Complexity
    ... your explanation of k and Shannon Information accords ... complexity may well be quantifiable, ... to the source string), k scales with the string, thus destroying the ... course, for most people, this description is very confusing since it ...
    (talk.origins)
  • Re: Suggested Alternative Unicode Implementation (for Rudy+ miscothers)
    ... ubiquity of the "string" datatype. ... I'm not so sure I see at as any more confusing than an already ... compile would still fail because the compiler would try to link against ... properly respected by any source units. ...
    (borland.public.delphi.non-technical)