Подробнее о сценарии языка Perl FlightScheduleHDML.pl
Подробнее о сценарии языка Perl FlightScheduleHDML.pl
Как было описано выше, когда пользователь производит выбор авиакомпании иопределяет номер рейса в файле FlightSchedule.hdml, приложение пересылаетданные сценарию FlightScheduleHOML.pl. Как вы понимаете, элементы в исходномкоде для отображения информации о рейсе этого сценария практически идентичны элементам сценария, описанного ранее в этой главе. Описанные нижеоператоры языка Perl создают исходный код формата HDML, который используется браузером для отображения информации о рейсе или сообщения об ошибке(если номер рейса неправильный):
#!/usr/bin/perl
read (STDIN, $Buffer, $ENV{'CONTENT_LENGTH'});
@data = split(/&/, $Buffer);
$AirCode = $data[0]; $FlightNum = $data[1];
if ($AirCode eq "SU") { $AirName = "Aeroflot";
if ($FlightNum eq "1") { $ArriveCity = "Moscow"; $ArriveTime = "8:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "New York"; $ArriveTime = "6:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "AC")
{ $AirName = "Air Canada";
if ($FlightNum eq "1") { $ArriveCity = "New York"; $ArriveTime = "10:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Boston"; $ArriveTime = "9:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "AF")
{ $AirName = "Air France";
if ($FlightNum eq "1") { $ArriveCity = "Paris"; $ArriveTime = "9:45 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "London"; $ArriveTime = "11:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "NZ")
{ $AirName = "Air New Zealand";
if ($FlightNum eq "1") { $ArriveCity = "Auckland"; $ArriveTime = "8:50 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Sydney"; $ArriveTime = "9:00 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($ AirCode eq "AS")
{ $AirName = "Alaska Airlines";
if ($FlightNum eq "1") { $ArriveCity = "Portland"; $ArriveTime = "6:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Las Vegas"; $ArriveTime = "7:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "AQ")
{ $AirName = "Aloha Airlines";
if ($FlightNum eq "1") { $ArriveCity = "Hilo"; $ArriveTime = "11:15 am"; } elsif ($FlightNum eq "2") { $ArriveCity = "Los Angeles"; $ArriveTime = "9:45 pm"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "HP")
{ $AirName = "America West";
if ($FlightNum eq "1") { $ArriveCity = "Las Vegas"; $ArriveTime = "10:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "PHoenix"; $ArriveTime = "9:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "AA")
{ $AirName = "American Airlines";
if ($FlightNum eq "1") { $ArriveCity = "New York"; $ArriveTime = "8:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Phoenix"; $ArriveTime = "9:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "TZ")
{ $AirName = "American Trans Air";
if ($FlightNum eq "1") { $ArriveCity = "Chicago"; $ArriveTime = "8:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "San Francisco"; $ArriveTime = "9:30 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "CO")
{ $AirName = "Continental";
if ($FlightNum eq "1") { $ArriveCity = "Boston"; $ArriveTime = "6:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Los Angeles"; $ArriveTime = "9:30 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($ AirCode eq "DL")
{ $AirName = "Delta";
if ($FlightNum eq "1") { $ArriveCity = "Atlanta"; $ArriveTime = "7:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Las Vegas"; $ArriveTime = "8:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "LH")
{ $AirName = "Lufthansa";
if ($FlightNum eq "1") { $ArriveCity = "Berlin"; $ArriveTime = "9:30 am"; } elsif ($FlightNum eq "2") { $ArriveCity = "Chicago"; $ArriveTime = "9:00 pm"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "JL")
{ $AirName = "Japan Airlines";
if ($FlightNum eq "1") { $ArriveCity = "Tokyo"; $ArriveTime = "9:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "New York"; $ArriveTime = "9:30 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "KL")
{ $AirName = "KLM Royal Dutch";
if ($FlightNum eq "1") { $ArriveCity = "London"; $ArriveTime = "10:00 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "New York"; $ArriveTime = "9:00 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "NW")
{ $AirName = "Northwest Airlines";
if ($FlightNum eq "1") { $ArriveCity = "Seattle"; $ArriveTime = "8:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Portland"; $ArriveTime = "7:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "QF")
{ $AirName = "Qantas Airlines";
if ($FlightNum eq "1") { $ArriveCity = "Melbourne"; $ArriveTime = "7:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Tokyo"; $ArriveTime = "9:30 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($ AirCode eq "QQ")
{ $AirName = "Reno Air";
if ($FlightNum eq "1") { $ArriveCity = "Reno"; $ArriveTime = "10:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Las Vegas"; $ArriveTime = "9:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "SR")
{ $AirName = "Swiss Air";
if ($FlightNum eq "1") { $ArriveCity = "New York"; $ArriveTime = "8:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Boston"; $ArriveTime = "6:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "TW")
{ $AirName = "TWA";
if ($FlightNum eq "1") { $ArriveCity = "Chicago"; $ArriveTime = "10:00 am"; } elsif ($FlightNum eq "2") { $ArriveCity = "Los Angeles"; $ArriveTime = "9:30 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "UA")
{ $AirName = "United Airlines";
if ($FlightNum eq "1") { $ArriveCity = "Las Vegas"; $ArriveTime = "10:00 am"; } elsif ($FlightNum eq "2") { $ArriveCity = "Boston"; $ArriveTime = "11:45 pm"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "US")
{ $AirName = "USAir";
if ($FlightNum eq "1") { $ArriveCity = "New York"; $ArriveTime = "8:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "Boston"; $ArriveTime = "6:45 am"; } else { $ArriveCity = "Unknown"; } }
elsif ($AirCode eq "VS")
{ $AirName = "Virgin Atlantic";
if ($FlightNum eq "1") { $ArriveCity = "London"; $ArriveTime = "10:30 pm"; } elsif ($FlightNum eq "2") { $ArriveCity = "New York"; $ArriveTime = "9:45 am"; } else { $ArriveCity = "Unknown"; } }
if ($ArriveCity eq "Unknown") {
$Deck = "Content-type: text/x-hdml
<HDML Version=3.0 Markable=True TTL=0>
<Display>
<Action Type=Accept Task=GO Label=Done Dest=../FlightSchedule/FlightSchedule.hdml Vars=AirCode=&FlightNum=>
$AirName flight $ FlightNum is not in the database. Try again.
</Display>
</HDML>";
print $Deck; } else { $Deck = "Content-type: text/x-hdml
<HDML Version=3.0 Markable=True TTL=0>
<Display>
<Action Type=Accept Task=GO Label=Done Dest=../FlightSchedule/FlightSchedule.hdml Vars=AirCode=&FlightNum=>
$AirName flight $FlightNum will arrive in $ArriveCity at $ArriveTime
</Display>
</HDML>";
print $Deck; }
Как вы видите, обе деки формата HDML используют элементы <Display> вывода сообщения на экран сотового телефона. Аналогично, обе деки используют элементы <Action> для того, чтобы пользователь мог вернуться в началеприложения.