[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] am I drunk.... code reduction? #2



> ?? I must be drunk? Doesn't 
> 
>    if ($r[0] =~ /^COMP/) {
>       $r[0] = $r[1];
>       if ((not $r[0] =~ /HCOMP/) and (not $r[0] =~ /GCOMP/) and (not
$r[0] =~ /CCOMP/)) {
>          $r[0] = "COMP";
>       }
>    }
> 
> reduce to 
> 
>    if ($r[0] =~ /^COMP/) {
>       $r[0] = "COMP";
>    } 
> 
> ??

[Answering my own question...]

No. If

   @r = ("COMPX", "HCOMP");

then the original code would leave $r[0] as "COMPX" but my reduction
would change it to "COMP".

Ok, I'm only half drunk... (the other example still stands AFAICT)

(That is *not* the way I would have written this original, but my
reduction was wrong.)

Reduction stab 2:

   if ($r[0] =~ /^COMP/) {
      if ($r[1] =~ /[HGC]COMP/) {
         $r[0] = $r[1];
      } else {
         $r[0] = "COMP";
      }
   }

Better, yes? No?

j