http://www.perlmonks.org?node_id=1086791


in reply to Re: Extracting single element from array to be printed in a one liner hash
in thread Extracting single element from array to be printed in a one liner hash

I got the following error when u changed the foreach loop to yours:
Please enter a string apple Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Use of uninitialized value $data in hash element at p3task6.pl line 30 +, <STDIN> line 2. Use of uninitialized value in string eq at p3task6.pl line 30, <STDIN> + line 2. Please enter a string
  • Comment on Re^2: Extracting single element from array to be printed in a one liner hash
  • Download Code

Replies are listed 'Best First'.
Re^3: Extracting single element from array to be printed in a one liner hash
by moritz (Cardinal) on May 20, 2014 at 14:07 UTC

      The OP wanted to type apples for example and have it say "fruits". To do this you need:

      if ( $key eq $input ) { ... }