Next Program Repair Shop 27

Repeated Code

      sub filetype {
          my $filename = shift;
          return "cc"     if $filename =~ /\.[ch](pp)?$/;
          return "perl"   if $filename =~ /\.(pl|pm|pod|tt|ttml|t)$/;
          return "php"    if $filename =~ /\.(phpt?|html?)$/;
          return "python" if $filename =~ /\.py$/;
          return "ruby"   if $filename =~ /\.rb$/;
          return "shell"  if $filename =~ /\.[ckz]?sh$/;
          return "sql"    if $filename =~ /\.(sql|ctl)$/;
          ...
      sub filetype {
          my $filename = shift;
          for ($filename) {
            return "cc"     if /\.[ch](pp)?$/;
            return "perl"   if /\.(pl|pm|pod|tt|ttml|t)$/;
            return "php"    if /\.(phpt?|html?)$/;
            return "python" if /\.py$/;
            return "ruby"   if /\.rb$/;
            return "shell"  if /\.[ckz]?sh$/;
            return "sql"    if /\.(sql|ctl)$/;

Next Copyright © 2006 M. J. Dominus