#!/usr/local/bin/perl
#Code is used to allow user to type in cities and dates, and returns the cheapest ticket

system "clear";						#clear screen

########	Set-up for user interface		#############

print "Use the following codes when entering dates of travel\n";
print "*" x 60, "\n\n";

print"January=Jan\tFebruary=Feb\tMarch=Mar\tApril=Apr\n";
print"May=May\t\tJune=Jun\tJuly=Jul\tAugust=Aug\n";
print"September=Sep\tOctober=Oct\tNovember=Nov\tDecember=Dec\n\n";

print "*" x 60, "\n\n";


print "Departure Airport:";
$dep=<STDIN>;
chomp ($dep);

print "Destination Airport:";
$des=<STDIN>;
chomp ($des);

open (LYNX, "lynx -source 'http://www.itn.net/cgi/air?stamp=NEWCOOKY*itn%2Ford%3DNEWREC,itn/air/united&airline=United&persons=1&air_avail=10&air_class=coach+%28lowest+avail.%29&depart=$dep&dest.0=$des&mon_abbr.0=Apr&date.0=16&hour_ampm.0=5+am&mon_abbr.1=Apr&date.1=23&hour_ampm.1=5+am&ecert_num=&rt_ow=Round+Trip&best_itins=2&return_to=best_itins
'
 |") or die "Can't open lynx: $!";

my @lines= <LYNX>;
my $total=0;

foreach(@lines){
	if (/USD/){
		$total++;
	}
}

my $search="@lines";

	for ($i=0; $i < $total; $i++){
        $search =~ m/(USD)/g;
	my $pos1=pos($search);

	my $price=substr($search, ($pos1-14),6);

	print "$price\n";

}
	
	 

print "The total amount of available fares is: $total\n";



