On 3/9/06, Brian McKee <[EMAIL PROTECTED]> wrote:

> What is a pattern match good for if it isn't for finding a substring
> in a string?

That's a fair question. A pattern match finds a match for a pattern,
not a substring. Patterns can have metacharacters, they can be
case-insensitive, they can be anchored, they can save data in memory
variables like $3. But index() looks for a matching identical
substring, and that's all. No metacharacters to worry about.

Because it's a simpler operation, using index() can be faster than the
corresponding pattern match. (Then again, maybe not: A lot of work has
gone into optimizing Perl's regular expression engine.) But speed
isn't the main reason to choose index(); it's clarity. It's a simpler
operation to understand than an escaped pattern match, so I usually
(but not always) go with index().

Thanks for asking!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to