wildguess123 has asked for the
wisdom of the Perl Monks concerning the following question:

Hi all.
I have the following code,
#!/usr/bin/perl -w

open(FILEHANDLE,'movies.txt');

@array2 =<FILEHANDLE>;

close FILEHANDLE;

open(FILEHANDLE2,'fruits.txt');

@array3 =<FILEHANDLE2>;

close FILEHANDLE2;

foreach $movie (@array2) {

chomp($movie);

$data {$movie} = "movies";

}

foreach $fruits (@array3) {

chomp($fruits);

$data {$fruits} = "fruits";

}

do{

print "Please enter a string \n";

chomp($input = <STDIN>);

foreach $key (keys(%data)){

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

print "$input is a $data{$key}\n";

}

}

} while ($input ne 0);
The elements in movies.txt is the following:

the blind side

iron man

star trek

gi joe
The elements in fruits.txt is the following:

orange

apple

pear

water melon

This is what I want to achieve. For example, when the user enters apples, It would be printed : apples is a fruits, and thats it. Another example, when I enter gi joe,it would print: gi joe is a movie. Now , I am facing the following problems, when I enter apples when the program ask the user to enter the string, it would not appear anything and would prompt us to enter again. How should I edit my code to fulfill the following above?
Thanks!

Comment on Extracting single element from array to be printed in a one liner hash

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