<!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>&nbsp;&nbsp;&nbsp; for my $base (qw{A C G T}) {</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $fuzzycode&nbsp; = $mid;</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $prebase_i&nbsp; = $i - 1;</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $postbase_i = $mid_length - $i;</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $fuzzycode =~ s{</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ^([ACGT]{$prebase_i})&nbsp;&nbsp;&nbsp;&nbsp; #capture bases, if any,
            before current base</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ([ACGT])&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; #current base</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ([ACGT]{$postbase_i})$}&nbsp; #capture bases, if any,
            after current base</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {$1$base$3}xms;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #replace current base
            with
            $base</tt><br>
          <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push @{ $mid_pools{$fuzzycode} }, $pool_name;</tt><br>
          <tt>&nbsp;&nbsp;&nbsp; }</tt><br>
          <tt>}</tt><br>
        </blockquote>
        Actually, I don't see any problem with this code.</blockquote>
      <br>
      Readability is the issue.&nbsp;&nbsp; IMHO, the author is using a
      sledgehammer
      when a peen hammer would do.&nbsp; Speedups are not the issue.&nbsp; 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>
      &nbsp;&nbsp;&nbsp; for my $base (qw{A C G T}) {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $fuzzycode = $mid;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; substr($fuzzycode, $i, 1, $base);<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; push @{ $mid_pools{$fuzzycode} }, $pool_name;<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "$fuzzycode\n";<br>
      &nbsp;&nbsp;&nbsp; }<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>