#!/usr/local/bin/perl ############################################################################# # list2: List the ice cream orders - with sorting capabilities ############################################################################# ($sort_by, $asc_desc) = @ARGV; # extract sort arguments $downImage = ""; $upImage = ""; print "Content-type: text/html \n"; print "\n"; $nameOpt = ($sort_by eq "N" && $asc_desc eq "a") ? "N+d" : "N+a"; # toggle $addrOpt = ($sort_by eq "A" && $asc_desc eq "a") ? "A+d" : "A+a"; # asc / $flavOpt = ($sort_by eq "F" && $asc_desc eq "a") ? "F+d" : "F+a"; # / desc if ($sort_by eq "N") { $nameIcon = ($asc_desc eq "a") ? $downImage : $upImage; } if ($sort_by eq "A") { $addrIcon = ($asc_desc eq "a") ? $downImage : $upImage; } if ($sort_by eq "F") { $flavIcon = ($asc_desc eq "a") ? $downImage : $upImage; } print " List all orders

List of ice cream orders - with Sort -

"; open (ORDERFILE, "< ../../data/order.file") || print "Cannot open file - $!"; while($rec = ) { chomp($rec); ($fname,$address,$flavor) = split(/:/,$rec); if ($sort_by eq 'N') { @array[$i++] = join('~',($fname,$address,$flavor)); } if ($sort_by eq 'A') { @array[$i++] = join('~',($address,$fname,$flavor)); } if ($sort_by eq 'F') { @array[$i++] = join('~',($flavor,$fname,$address)); } } if ($asc_desc eq "a") { @array = sort @array; } # sort ascending if ($asc_desc eq "d") { @array = reverse sort @array; } # sort descending for ($i=0; $i<@array; $i++) { if ($sort_by eq 'N') { ($fname,$address,$flavor) = split(/~/, @array[$i]); } if ($sort_by eq 'A') { ($address,$fname,$flavor) = split(/~/, @array[$i]); } if ($sort_by eq 'F') { ($flavor,$fname,$address) = split(/~/, @array[$i]); } $address =~ s/__/
/g; print "
\n"; } print "
Name $nameIcon Address $addrIcon Flavor $flavIcon
$fname $address $flavor
";