Paul said:
Smitty said:
Bernard El-Hagin wrote:
I am wondering about the use of the \s regex construct within a
string vs using a space character.
They are not the same. \s matches [\ \t\r\n\f], not just a space.
Correct, but that is not my question.
Your question made no sense.
Sure it did, you probably meant to say that you didn't understand it.
Mmm, no, I'm guessing Xho, and most of us, understood your question
perfectly. In fact, it was understood so well as to realize that it
was nonsensical.
Appearantly not, but I'll get to that later.
You might just as well have asked "Is there any
advantage of printing 'Hello World' over multiplying $foo by $bar?"
Well, no, this is completely different, perhaps a better analogy would
be:
Is there any advantage to asking a person holding a basket that you
know to contain fruit, "Does your basket contain an apple, or a pear,
or a peach or a banana" as apposed to asking "Does your basket contain
an apple". Clearly in this case if you are only interest in knowing if
the basket contains an apple, you would ask so. And so it *probably*
is with perl and the difference between /\s/ and / /
It makes no sense to ask if one has an advantage over the other.
Well, let's think about that statement.
Given that I do not have any interest in reviewing the source code to
the perl regex engine, is it reasonable to think that perhaps there is
a possibility that the regex engine might perform some query
optimisation on /\s/ which might not happen with / / ?
Or maybe the construct (?:\s\w+)+ is somehow more efficiently processed
than (?: \w+)+
You see, I don't know, and so my question
Is there any advantage in using this regex
/^\w+(?:\s\w+)+$/
over this one
/^\w+(?: \w+)+$/ -- ie: s/\\s/ /g
is very reasonable, and sensible
Yes, I read about that, but I was put off bothering with it when I read
such caveats as
"Short tests may produce negative figures..." and "...CPU scheduling
and other operating system factors may complicate the attempt ..."
Which is pretty much what I was alluding to in my comment above.