in reply to **HomeWork** Trying to search an array and match it to a user input

Some additional thoughts...
# Since you are pre-defining the cities, you don't really need the spl +it. # Simply pre-populate an array my $myCities = "Baltimore:Chicago:Los Angeles:New York:San Diego:"; my @myCities = split(':', $myCities); print "Please pick one of the following cities by entering any portion + of the beginning of the city +name:(Baltimore Chicago Los Angeles New York San Diego)\n"; # Use the above array to populate the names. That way you don't have t +o do it twice. chomp (my $input_city = <STDIN> ); # Take a look at 'for' and '$_' for the loop foreach $city (@myCities) { # As has been noted, use 'eq' (strings) instead of '==' (numbers) # Better still, use a regular expression to be able to match 1 or +more letters # and, if all you want is the print output, take a look at 'unless +' if ( $input_city == $myCities ) { #exists; } else { print "I'm sorry,we no longer tour LA, please try again.\n"; } }
  • Comment on Re: **HomeWork** Trying to search an array and match it to a user input
  • Download Code