monkfan has asked for the wisdom of the Perl Monks concerning the following question:
Is it true that 'substr' function can be rewritten with regexp all the time? If so when is it better to use which? Any rule of thumb?sub hamming_distance_string{ #String length is assumed to be equal my ($a,$b) = @_; my $len = length ($a); my $num_match=0; for (my $i=0; $i<$len; $i++) { ++$num_match if substr($a, $i, 1) eq substr($b, $i, 1); } return $num_match; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Substr versus Regexp
by trammell (Priest) on Dec 31, 2004 at 15:56 UTC | |
|
Re: Substr versus Regexp
by sgifford (Prior) on Dec 31, 2004 at 22:06 UTC | |
|
Re: Substr versus Regexp
by Courage (Parson) on Dec 31, 2004 at 19:30 UTC | |
|
Re: Substr versus Regexp
by nornagon (Acolyte) on Jan 01, 2005 at 05:17 UTC |