# Dirk Duclos
# ID: 001179711


#!/usr/bin/perl
use strict;
use warnings;

my $infilename = '';
my $outfilename = '>';
my $word;

while (@ARGV) {                         # parse command line arguments 
  if ($ARGV[0] eq '-f') {
    shift;                              # move array elements up 
    $infilename = $ARGV[0];
    
    shift;
    if ($ARGV[0] eq '-o')
    {
        shift;
        $outfilename = $ARGV[0];
        shift;
    } 
    next;  
}
  
  elsif ( $ARGV[0] eq '-h') {           # display usage 
     print "\nUsage: lab06.pl [-h] -f <infile> -o <outfile>\n\n";
     shift;
     if (!@ARGV) {
        exit;
     }
     else {
       next; }
  } 
  else {   
     shift;                             # unknown argument so skip it
     next;
  }
}
open(INFILENAME, $infilename);
open(OUTFILENAME, $outfilename);

    my $line;
    my @words;

while(<INFILENAME>)
{

  # remove CR or LF from $_
  chomp;                        

  # assign the default current line $_ to another string
  $line = $_;                   
   
  @words = split ',', $line;
  foreach(@words)
  {
      my $value = 0;
      do
      {
      $word = $_; 
      $word =~ tr/A-Z/a-z/;      # make lowercase  
      $value = $value+1;
      }until($value==12);
      print "$word,"; 
  }
print "\n";
}     
close(INFILENAME);
close(OUTFILENAME);
