use warnings;
use strict;
use Data::Dump;
my @trip = ("Chicago", "Saint Looey", "Joplin", "OKC", "Amarillo",
"Gallup", "Flagstaff", "Winona", "Kingman", "Barstow",
"San Bernandino", "LA");
my %cities = ( "Amarillo" => { state => "TX" },
"Barstow" => { state => "CA" }, "Chicago" => { state => "IL" },
"Flagstaff" => { state => "AZ" }, "Gallup" => { state => "TX" },
"Joplin" => { state => "MO" }, "Kingman" => { state => "AZ" },
"LA" => { state => "CA" }, "OKC" => { state => "OK" },
"Saint Looey" => { state => "MO" },
"San Bernandino" => { state => "CA" },
"Winona" => { state => "AZ" }, );
for my $i (0..$#trip-1) {
my ($from,$to) = @trip[$i,$i+1];
print "$from, $cities{$from}{state} to $to, $cities{$to}{state}",
$cities{$from}{state} ne $cities{$to}{state}
? " - Mann Act!" : (), "\n";
}
print "\n##### Alternative #####\n";
$cities{$_}{city} = $_ for keys %cities;
$_ = $cities{$_}//die("bad city $_") for @trip;
dd \%cities, \@trip;
for my $i (0..$#trip-1) {
my ($from,$to) = @trip[$i,$i+1];
print "$from->{city}, $from->{state} to $to->{city}, "
."$to->{state}", $from->{state} ne $to->{state}
? " - Mann Act!" : (), "\n";
}
####
Chicago, IL to Saint Looey, MO - Mann Act!
Saint Looey, MO to Joplin, MO
Joplin, MO to OKC, OK - Mann Act!
OKC, OK to Amarillo, TX - Mann Act!
Amarillo, TX to Gallup, TX
Gallup, TX to Flagstaff, AZ - Mann Act!
Flagstaff, AZ to Winona, AZ
Winona, AZ to Kingman, AZ
Kingman, AZ to Barstow, CA - Mann Act!
Barstow, CA to San Bernandino, CA
San Bernandino, CA to LA, CA
##### Alternative #####
do {
my $a = {
"Amarillo" => { city => "Amarillo", state => "TX" },
"Barstow" => { city => "Barstow", state => "CA" },
"Chicago" => { city => "Chicago", state => "IL" },
"Flagstaff" => { city => "Flagstaff", state => "AZ" },
"Gallup" => { city => "Gallup", state => "TX" },
"Joplin" => { city => "Joplin", state => "MO" },
"Kingman" => { city => "Kingman", state => "AZ" },
"LA" => { city => "LA", state => "CA" },
"OKC" => { city => "OKC", state => "OK" },
"Saint Looey" => { city => "Saint Looey", state => "MO" },
"San Bernandino" => { city => "San Bernandino", state => "CA" },
"Winona" => { city => "Winona", state => "AZ" },
};
(
$a,
[
$a->{"Chicago"},
$a->{"Saint Looey"},
$a->{"Joplin"},
$a->{"OKC"},
$a->{"Amarillo"},
$a->{"Gallup"},
$a->{"Flagstaff"},
$a->{"Winona"},
$a->{"Kingman"},
$a->{"Barstow"},
$a->{"San Bernandino"},
$a->{"LA"},
],
);
}
Chicago, IL to Saint Looey, MO - Mann Act!
Saint Looey, MO to Joplin, MO
Joplin, MO to OKC, OK - Mann Act!
OKC, OK to Amarillo, TX - Mann Act!
Amarillo, TX to Gallup, TX
Gallup, TX to Flagstaff, AZ - Mann Act!
Flagstaff, AZ to Winona, AZ
Winona, AZ to Kingman, AZ
Kingman, AZ to Barstow, CA - Mann Act!
Barstow, CA to San Bernandino, CA
San Bernandino, CA to LA, CA
####
use warnings;
use strict;
use Data::Dump;
use List::Util 'pairs';
use List::MoreUtils 'mesh';
my @trip = ("Chicago", "Saint Looey", "Joplin", "OKC", "Amarillo",
"Gallup", "Flagstaff", "Winona", "Kingman", "Barstow",
"San Bernandino", "LA");
my @states = ("IL", "MO", "MO", "OK", "TX", "TX", "AZ", "AZ",
"AZ", "CA", "CA", "CA" );
my @legs = map {@trip[$_,$_+1]} 0..$#trip-1;
printf "%15s to %-15s\n", $_->[0], $_->[1] for pairs @legs;
my %info;
$info{$_->[0]}{state} = $_->[1] for pairs mesh @trip, @states;
dd \%info;
__END__
Chicago to Saint Looey
Saint Looey to Joplin
Joplin to OKC
OKC to Amarillo
Amarillo to Gallup
Gallup to Flagstaff
Flagstaff to Winona
Winona to Kingman
Kingman to Barstow
Barstow to San Bernandino
San Bernandino to LA
{
"Amarillo" => { state => "TX" },
"Barstow" => { state => "CA" },
"Chicago" => { state => "IL" },
"Flagstaff" => { state => "AZ" },
"Gallup" => { state => "TX" },
"Joplin" => { state => "MO" },
"Kingman" => { state => "AZ" },
"LA" => { state => "CA" },
"OKC" => { state => "OK" },
"Saint Looey" => { state => "MO" },
"San Bernandino" => { state => "CA" },
"Winona" => { state => "AZ" },
}