Re: Choosing between Regexp and Substr

2005-01-06 Thread John W. Krahn
Edward Wijaya wrote: Seems that John's regex approaches are (much) faster: Rate HD_string HD_jkrahn2 HD_jkrahn1 HD_string 203251/s -- -18% -76% HD_jkrahn2 247033/s22% -- -71% HD_jkrahn1 848840/s 318% 244% -- [snip] sub h

Re: Choosing between Regexp and Substr

2005-01-06 Thread Edward Wijaya
Seems that John's regex approaches are (much) faster: Rate HD_string HD_jkrahn2 HD_jkrahn1 HD_string 203251/s -- -18% -76% HD_jkrahn2 247033/s22% -- -71% HD_jkrahn1 848840/s 318% 244% -- __BEGIN__ #!/usr/bin/perl -w us

Re: Choosing between Regexp and Substr

2005-01-03 Thread Jenda Krynicky
From: "John W. Krahn" <[EMAIL PROTECTED]> > Peter Scott wrote: > > In article <[EMAIL PROTECTED]>, > > [EMAIL PROTECTED] (Edward Wijaya) writes: > > > >>BTW, can you explain what's the difference between these two? > >> > >>>sub hamming_distance_string { ( $_[0] ^ $_[1] ) =~ tr/\0// } > > > > In

Re: Choosing between Regexp and Substr

2005-01-03 Thread John W. Krahn
Peter Scott wrote: In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Edward Wijaya) writes: BTW, can you explain what's the difference between these two? sub hamming_distance_string { ( $_[0] ^ $_[1] ) =~ tr/\0// } In a scalar context, tr/// returns the count of the number of characters seen. sub

Re: Choosing between Regexp and Substr

2005-01-03 Thread Peter Scott
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Edward Wijaya) writes: >BTW, can you explain what's the difference between these two? > >> >> sub hamming_distance_string { ( $_[0] ^ $_[1] ) =~ tr/\0// } In a scalar context, tr/// returns the count of the number of characters seen. >> sub hamm

Re: Choosing between Regexp and Substr

2005-01-03 Thread Edward Wijaya
Thanks so much for the reply John, On Mon, 03 Jan 2005 04:07:05 -0800, John W. Krahn <[EMAIL PROTECTED]> wrote: I don't know if I am a master but I wouldn't use a regular expression. In my eyes, you certainly is a master! BTW, can you explain what's the difference between these two? sub hamming_di

Re: Choosing between Regexp and Substr

2005-01-03 Thread Jenda Krynicky
From: "Octavian Rasnita" <[EMAIL PROTECTED]> > If you can use substr(), use it, because it works much faster than > regexp. > > Teddy Nope. One substr() will of course be quicker than one regexp application, but a loop containing substr() will most of the time slower than a single regexp. You

Re: Choosing between Regexp and Substr

2005-01-03 Thread John W. Krahn
Edward WIJAYA wrote: Dear friends, Hello, After a couple of months dwelling into Perl scripting especially in manipulating strings, I found myself resorting to use "substr" function a lot. I had a feeling that the most of the "substr" function can be replaced with regexp in any cases. For ex

Re: Choosing between Regexp and Substr

2005-01-03 Thread Octavian Rasnita
If you can use substr(), use it, because it works much faster than regexp. Teddy - Original Message - From: "Edward WIJAYA" <[EMAIL PROTECTED]> To: Sent: Sunday, January 02, 2005 5:08 PM Subject: Choosing between Regexp and Substr > Dear friends, > > After a

Choosing between Regexp and Substr

2005-01-02 Thread Edward WIJAYA
Dear friends, After a couple of months dwelling into Perl scripting especially in manipulating strings, I found myself resorting to use "substr" function a lot. I had a feeling that the most of the "substr" function can be replaced with regexp in any cases. For example the simple code below.