Chas. Owens wrote:
On Wed, Apr 9, 2008 at 7:14 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote:
Chas. Owens wrote:
snip
There are at least three downsides to using the substr function:
1. multiple function calls
2. lots of typing
3. no guarantee that the input string is in the right format

 That comment surprised me. While I can agree that a regex makes it easier
to validate input, the difference in typing is insignificant, and the regex
is often more expensive to run than multiple calls for substr(). Please see
the benchmark below.
snip

To be fair you must ensure the input data is in the right format
before using the calls to the substr function.

I suppose it depends on the nature of the input data. But as long as the code shall take care of both validation and data extraction, yes, then a capturing regex is often faster.

It was your talking down substr() in general that made me react. The difference in CPU time is normally negligible, so I'd say that it boils down to a matter of personal preferences.

The FAQ entry

    perldoc -q "N characters"

doesn't mention regular expressions, btw.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

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


Reply via email to