I am trying to search a scalar for a word that is in another scalar and I can't seem to get it to work. I found other postings but I could not get anything to work.
For example. If the first variable has "Plumbing" and a second variable has "ABC Plumbing", I want to know if the variable holding "ABC Plumbing" has the word "Plumbing" in it.
I have something like this but it is not working.
$sic = 1711;
$hash{$sic}{BUS} = 'Plumbing'; # A keyword in a business name
$hash{$sic}{CAT} = 'Plumbing'; # Category
$str[1] = 'Elite Plumbing';
foreach $sic (keys %hash){
# if the word in $hash{$sic}{BUS} is found in $str[1],
# I want to know.
# if ($hash{$sic}{BUS} =~ /$str[1]/) # This wont work.
if (grep { $hash{$sic}{BUS} == $_ } $str[1] ){ # Nope
# $str[38] = $hash{$sic}{CAT};
# $str[39] = $hash{$sic}{BUS};
print "Found one. Bus name is $str[1] and cat is " . $hash{$sic}
+{CAT} . " and sic is " . $str[39] ."\n";
}
}
I know that it has to be simple but I can't figure it out. Can someone tell me what I am missing?
Since I have posted this, I noticed that I am using grep wrong.
Thanks
Kevin