Hi Anant,

>>I want to search whether a scalar '$a' contains any one of value of an
array
>>'@arr'.
>>How it may be done?
>>as its not correct : print "found" if $a =~ /@arr/;

#!/usr/bin/perl
use strict;
use warnings;

 my @arr=qw(fry ring apple law);
 print "Enter the string you are searching for:";
 chomp(my $search=<STDIN>); # you may have to check, if input is not string

 grep {print "found: $_" if/\b$search\b/}@arr;

 #grep compare your search with each array element
 # using $_ and then print out if item is found.
 # To make it plain you can ALSO use a foreach loop instead of grep,
 # iterate over your array element, comparing them each element
 # with your search item.

 foreach my $found(@arr){
   if($found=~/$search/){
     print "found: ",$found,"\n";
   }
 }

Reply via email to