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!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |