It seems I ... will have to use regex
This 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:

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;
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.

-- 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.