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

A few more points: If you have studied hashes, using that construct would make your code considerably simpler, and easier to read.

Good luck.

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

  • Comment on Re: **HomeWork** Trying to search an array and match it to a user input

Replies are listed 'Best First'.
Re^2: **HomeWork** Trying to search an array and match it to a user input
by Arif (Acolyte) on Mar 27, 2008 at 18:06 UTC
    You can also take a look at the module Text::Abbrev. It makes it easy to work with abbreviations of strings.
    %hash = abbrev (split(':', "Baltimore:Chicago:Los Angeles:New York:San Diego:"));
    chomp (my $input_city = <STDIN> );
    if (exists $hash{$input_city}) { ...... }