in reply to Re^2: **HomeWork** Trying to search an array and match it to a user input
in thread **HomeWork** Trying to search an array and match it to a user input

Your foreach loop will loop over only one element, $input_city. What you want to do is loop over everything in @myCities. The syntax looks like this:

foreach my $city ( @myCities ) { # $city is 'Baltimore' the fist time # $city is 'Chicago' the second time # etc. }

You can see this in action with an example like this:

foreach my $city ( @myCities ) { print "\$city = '$city'\n"; }

A simple print (or warn) like that can be very helpful when debugging.

What you could do is create a variable to hold the city that's found. This variable should start with a known bogus value (such as the empty string). Then loop through your cities and see if any one of them matches the $input_city. If there is a match, set the found city variable to the matching city. After the loop, check if the bogus value is still there or if some city was found. If a city was found, check if it's Los Angeles, and handle it accordingly.