Brian F. Yulga wrote:

my @mail_types = qw( avenue road box lane );
my @words = split /\s/, $fields;
my $count = grep {
    my $found;
    foreach my $street ( @mail_types ) {
        if ( /\b$street\b/i ) {
            $found++;
            last;
        }
    }
    $found;
} @words;
print qq(found $count address types\n) if ( $count > 1);


I think I was wrong; this is even longer, and too convoluted.... I'm sure there's a better way...


Of course, two minutes after I send to the list, I get a much better idea. My apologies for spamming all of you.... How about this:


my @mail_types = qw( street road box lane );

my $regex;
$regex .= q(\b) . $_ . q(\b|) foreach ( @mail_types );
$regex = substr $regex, 0, -1;

my $count = grep /$regex/i, @words;

print qq(found $count\n) if ( $count > 1);


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to