<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 10/20/2010 8:59 AM, Rick Westerman wrote:
<blockquote cite="mid:4CBEE7AF.2080309@purdue.edu" type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<br>
<blockquote cite="mid:4CBEE486.6000608@purdue.edu" type="cite">
The
code in question (with extra comments):<br>
<tt><br>
</tt>
<blockquote><tt>for my $i ( 1 .. $mid_length ) {</tt><br>
<tt> for my $base (qw{A C G T}) {</tt><br>
<tt> my $fuzzycode = $mid;</tt><br>
<tt> my $prebase_i = $i - 1;</tt><br>
<tt> my $postbase_i = $mid_length - $i;</tt><br>
<tt> $fuzzycode =~ s{</tt><br>
<tt> ^([ACGT]{$prebase_i}) #capture bases, if any,
before current base</tt><br>
<tt> ([ACGT]) #current base</tt><br>
<tt> ([ACGT]{$postbase_i})$} #capture bases, if any,
after current base</tt><br>
<tt> {$1$base$3}xms; #replace current base
with
$base</tt><br>
<tt> push @{ $mid_pools{$fuzzycode} }, $pool_name;</tt><br>
<tt> }</tt><br>
<tt>}</tt><br>
</blockquote>
Actually, I don't see any problem with this code.</blockquote>
<br>
Readability is the issue. IMHO, the author is using a
sledgehammer
when a peen hammer would do. Speedups are not the issue. The
following is much more clear ... especially to the the novice Perl
programmer who is not that familiar with regexes.<br>
<br>
<br>
for my $i ( 0 .. $mid_length - 1) {<br>
for my $base (qw{A C G T}) {<br>
my $fuzzycode = $mid;<br>
substr($fuzzycode, $i, 1, $base);<br>
push @{ $mid_pools{$fuzzycode} }, $pool_name;<br>
print "$fuzzycode\n";<br>
}<br>
}<br>
<br>
<br>
Explaining substr should be a piece of cake compared to regex
captures
and replacements.<br>
<br>
</blockquote>
Your code is more compact. But the original code spoke to me. I
could immediately tell what the author intended to do. Your more
compact implementation does something very similar to what the
original code does, but were I to read it de novo, I doubt I would
have any idea what it was doing. <br>
<br>
Regex captures and replacements are important parts of perl. So they
need to be explained sometime. I think you guys are hitting the "I
saw a problem and decided to use a regex to solve it, now I have two
problems" meme too hard. Unfortunately the meme is funny, which
gives it more persistence than it should be allocated. <br>
<br>
That said, now that I do understand the code, I would go with the
more compact form.<br>
<br>
Phillip<br>
</body>
</html>