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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.