-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 
Sent: Monday, March 06, 2006 2:07 PM
Subject: regexp vs substr for string capture?
>Wizards, 
>I thought regexp was the fastest way to pull strings out of another string;
certainly faster >than substr(). It seems I was wrong, as the following code
>showed

I couldn't tell you this for sure but my common sense response is that a
regex has to do lots of comparing and the more complex it is the more
comparing it has to do.  Your call to substr has two hard coded fixed values
(19 and -5) and requires no comparing.  I'm not surprised to find that's so
much faster.   What you probably heard was that the entire process of
figuring out where to get the substring would take longer than a regex.
Especially for variable data!  The more variance it has the better a general
purpose regex will perform vs. some logic you wrote and a call to substr.
If you have fixed width *by all means* use substr!  

Most the time a regex is used it is with variable data lengths and/or
unknown input values.  Try this one again with 100 lines of xml with
different data on each line. The logic required to use a substr to pull out
the tag on each line would be massive.

I could be off base but that's my common sense understand if what's going on
here, in your example.

-Wayne


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to