@Dave: Here is my complete sub code with sample data. I would like to match $namecnt with field1 from the flat file so it wont match every variation of David Dave Tom Thomas etc:
_DATA_sub namecount { my %count; open(INPUT, "$config::namedata"); # PULLS NAMES FROM FLAT FILE open(OUTPUT, ">$config::namecountdata"); # PUTS NAME COUNT IN NEW FILE my $namecnt='David|Tom|Sam|Will|Dave|William|Thomas'; while(<INPUT>){ my @words = split(":"); foreach my $word (@words){ if($word=~/($namecnt)/io){ $count{$1}++; } } } foreach my $word (sort keys %count) { printf("%39s %-14s %-19s %6s", colored("There are",'cyan bold'), colored("$count{$word}",'yellow bold'), colored("$word",'cyan bold'), colored("Name(s)\n",'cyan bold') ); print OUTPUT "There are $count{$word} $word Name(s)\n"; } close INPUT; close OUTPUT; } # END SUB
In reply to Re^2: Word Count and Match
by PilotinControl
in thread Word Count and Match
by PilotinControl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |