#!/usr/local/bin/perl -s

if ($#ARGV<0) {
  print <<'EOH';
  Usage: tab2com -o [oldfiles]
  This script converts data files from tab-delimited to comma-delimited.
  By default, a new file with a .com suffix is written.  If the -o option
  is used, the old file is overwritten.
EOH
}

foreach $file (@ARGV) {
  open(oldfile,"$file");
  open(newfile,">$file.com");
  while($_ = <oldfile>){
    $_ =~ s/\t/\, /g;
    print newfile "$_" if !($_ =~ /""/);
  }
  close(oldfile);
  if ($o) {
    system("mv $file.com $file");
  }
}
