#!/usr/bin/perl

my $fname    = $ARGV[0];
my $listc    = $ARGV[1];
my $ofname   = $ARGV[2];


if( @ARGV  ne 3 )
  {
    print "Wrong number of arguments!\n";
    print "Syntax: ./producePriorityList.pl results.txt list_cand.txt list_priority\n";
    exit( 1 );
  }


open( CANDFILE, $listc )    or die "Cannot open: $!";
open( OUTFILE, ">$ofname" ) or die "Cannot write to: $!";


while ( <CANDFILE> )
{
  my $name = $_;
  $name =~ s/\n//g;
  my $score = -2;

  open( MYFILE, $fname )      or die "Cannot open: $!";
  while ( <MYFILE> )
    {
      my @parts = split " ", $_;
      $parts[5] =~ s/x/\-/g;
      @parts2 = split "_", $parts[5];
      if( $parts2[0] eq $name )
	{
	  if( $score lt $parts[10] ) 
	    {
	      $score = $parts[10];
	    }
	}
    }
  print OUTFILE $score." ". $name."\n";
  close( MYFILE );
}

system( "sort -nr $ofname > $ofname.srt" );





