#!/usr/bin/perl -w

#### ps2p-2.pl

#    VERSION: 1 (24 September 2003)
#    PURPOSE: Yours to find out
#    INPUT: From two files with format:
#       GeneID GeneID
# 
#    OUTPUT: One file with same format

############## LIBRARIES AND PRAGMAS ################
  use strict;

#################### VARIABLES ######################

  my @input_list1;             # Stores all above values
  my @input_list2;             # Stores all above values
  my @combined_list;
  my @final_list;
  my $line;                   # One line from input file
  my $LF = "\n";              # Linefeed

###################### FILES ########################

#### OPEN INPUT FILES

  my $input1_path = 'ps2p-2-data1.txt';
  my $input2_path = 'ps2p-2-data2.txt';

#### OPEN OUR OUTPUT FILE

  my $result_path = 'EDsubjects.txt';
  open RESULT, ">$result_path" or die "Can't open $result_path: $!\n";

################### MAIN PROGRAM ####################

  @input_list1 = Get_list_from_file($input1_path);
  @input_list2 = Get_list_from_file($input2_path);

  @combined_list = (@input_list1, @input_list2);
  @final_list = sort (@combined_list);

  print join($LF, @final_list);
  print RESULT join($LF, @final_list);

# FINAL STATS
  print $LF, $LF;
  print "Size of first list: ", Size(@input_list1), $LF;
  print "Size of second list: ", Size(@input_list2), $LF;
  print "Size of combined list: ", Size(@combined_list), $LF;

#################### SUBROUTINES ####################

#### GET_LIST_FROM_FILE
# Prints info stored in @query_info
# If there's no info there (i.e., the first time through), print nothing

sub Get_list_from_file {

   (my $file_path) = @_;
   open FILE, "<$file_path" or die "Can't open $file_path: $!\n";

   my @list;
   my $line = <FILE>;
   while (defined $line) {
      chomp $line;
      push @list, $line;
      $line = <FILE>;
   }
   return @list;
}

#### SIZE (array)
# Returns the number of elements in the array

sub Size {
  my $size = @_;
  return $size;
}