Hello Daniel!

Friday, May 6, 2005, 11:16:54 PM, you wrote:

DFS> .....
DFS> The heart of the matter seems to be a difference in expectations.  I

Of course, but isn't my expectation *natural*?

DFS> understand why you could expect matches() to behave that way.  However,
DFS> its documentation explains that it's not the same as ^pattern$.  I'll

In fact, it only states the difference without any real explanation.
Let me cite:
> matches() literally looks for an exact match according to the rules
> of Perl5 expression matching. Therefore, if you have a pattern
> foo|foot and are matching the input foot it will not produce an exact match 

How "therefore"???
Anyone who finds it clear (esp. Kevin Markey), please guess which of
the following is true: 

/foot?/ matches "foot"
/foot?/ matches "foo"
/foot??/ matches "foot"
/foot??/ matches "foo"


DFS> matches() tests whether or not a pattern matches the input it is given.
DFS> This means that the matching process must start at the beginning of
DFS> the input and stop at the end of the input.  If the matching process stops
DFS> before the end of the input, then there's no match.  The method answers
DFS> the question "Is this input character sequence a member of the set of all
DFS> the character sequences matched by this pattern?"

Ooops!
The matching set for "foo|foot" is {"foo","foot"}.
The matching set for "foot|foo" is ***the same***. Order doesn't
matter in sets.

DFS> It may make more sense thinking about it this way.  matches() returns true
DFS> if and only if S =~ m/(P)/ is true and $1 equals S.  For example:

DFS>   sub matches(@) {
DFS>     my ($pat, $str) = @_;
DFS>     $str =~ m/($pat)/;
DFS>     return ($str eq $1);
DFS>   }

DFS>   printf "%d\n%d\n", matches("foo|foot", "foo"), matches("foo|foot", 
"foot");

Yes, that's it. Something like that had to be in the docs.

DFS> In my opinion, the important thing is for the behavior to be documented.
DFS> If it's not sufficiently clear, then we ought to make it more clear.
DFS> Documentation patches are welcome.

DFS> Now, one can argue that we should add a validate() method specifically
DFS> for input validation with the behavior you expected.  My opinion

I'd say that the best method would be the "matches()" itself (see my
first remark).
Otherwise the question is closed.
Thanks a lot for your patience.

DFS> daniel

-- 
Best regards,
 Sergey



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to