It seems I ... will have to use regexThis is not correct. Regexes are for cases where you don't know what to search for exactly, you just now how the pattern looks like, e.g. two letters followed by 3 or more digits ending with a newline. In your case, you are searching for a literal string and thus you can use index (see perldoc -f index).
Assuming that the long filenames are not broken across lines and the same filename does not appear multiple times on on line, the following should do what you want:
The trick is to define the hash %exe the other way around, so that it gives the short name when accessed with the long filename.use strict; @ARGV = ('security.txt') unless @ARGV; my %exe = ( 'C:\Program Files\Internet Explorer\IEXPLORE.EXE' => 'Catalog', 'D:\crime\Reader\AcroRd32.exe' => 'Crime', ); my %count; while (<>) { for my $filename (keys %exe) { %count{ $exe{filename} }++ if index($_, $filename) > -1; }; } print "Name: $_ Count: $count{$_}" for keys %count;
-- Hofmator
In reply to Re4: Help - Counting text - Associative Array? (I was Annon Monk)
by Hofmator
in thread Help - Counting text - Associative Array?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |