in reply to searching a scalar for a word. Should I use grep?
use strict; use warnings; my %hash = (1711 => {BUS => 'Plumbing', CAT => 'Plumbing'}); my @str = ('Elite Plumbing', 'Wonderfull Welding'); for my $key (keys %hash) { my @matches = grep {-1 < index $_, $hash{$key}{BUS}} @str; next unless @matches; print "Match for $hash{$key}{BUS} in:\n "; print join "\n ", @matches; }
Prints:
Match for Plumbing in: Elite Plumbing
|
|---|