# Break up each line into words, and put all words into a hash that counts frequencies.
# 1st argument: name of input file
# 2nd argument: name of output file

	if ( scalar( @ARGV ) >=  2 )
	{ 
				$TheFile = $ARGV[0];
				$OutputFile = ">" . $ARGV[1];
	} 

	else 

	{ 	print  "Not enough arguments given to operate; goodbye."; 
		exit;
	}


	open (INFILE, $TheFile) or die "The file $TheFile could not be found";
	open (OUTFILE, $OutputFile);




	$LineCount =0; 					#This is unnecessary in PERL;

	while (<INFILE>)        
	{
		$LineCount =  $LineCount + 1;
		$TheLine= $_;					# unnecessarily explicit in real PERL
		chomp ($TheLine); 				# Removes the final carriage-return of the line.

		@Words=split(/ /, $TheLine); 		# Split each line up where there is a space, and call this @Words;
		while ($Word = shift ( @Words ) )	# Go through a loop, continuing as long as @Words has something in it so it can be shifted out!
		{
			if (exists $Frequency {$Word}  )	# if the has "@Frequency" has an entry for $Word...
			{
				  $Frequency {$Word}  ++;                              
			}
			else								# if it doesn't have an entry for #Word...
		   {                                              
				  $Frequency {$Word } = 1.0;  
		   }          

		}
		 
                 
	}

	close INFILE;



	@SortedList = sort  keys(%Frequency) ;		# A sorted list of our words...
	
	while ( $Word = shift ( @SortedList ) )
	{
		print OUTFILE $Word, "\n";		
	}	



	close OUTFILE;