#! /usr/bin/perl

# This program reads names and separates them depending if they have only 
# two words (first_name last_name), or more than two words for further 
# checking (could be several first names or several last names).

# (1) quit unless we have the correct number of command-line args
$num_args = $#ARGV + 1;
if ($num_args != 3) {
  print "\nUsage: prog.pl infile outfile2 outfilemorethan2\n";
  exit;
}

#Open three files

$infile=$ARGV[0];
$outfile2=$ARGV[1];
$outfile3m = $ARGV[2];

open(INF,$infile) or die "Can't open code name file: $!\n";
open(OUTF2,">$outfile2");
open(OUTF3M,">$outfile3m");

# Main loop: read each name and output adequately

while ($line = <INF>)
 {   
   @words = split(" ",$line);
   $szw = @words;   
   if ($szw == 2) {print OUTF2 "$line";   
       } else {print OUTF3M "$line";}
 }


close(INF);
close(OUTF2);
close(OUTF3M);
