Help - Counting text - Associative Array?

From: Sam Lowry (mr_lowry_at_hotmail.com)
Date: 03/19/04


Date: 19 Mar 2004 08:59:03 -0800

Greetings. I am trying to do something which should elementary for
Perl, but I have only been able to find bits and pieces on it. When I
put the bits together they do not work. Maybe I am going in the wrong
direction.

I want to count several strings of text in a file (security.txt) and
output the counts with a brief description of each. I have tried
specifying the descriptions (name) and the strings (exe) in the array
within the perl script. I can open the file to search ok, but the
counting/output doesn't work. It seems to count every line in the
file. The strings are not on their own lines in security.txt.

The goal is to see something like:

Name: Catalog Count:2
Name: Crime Count:1

Yes I am a newb, so if anyone can point me in the right direction I'd
sure appreciate it. TIA, Sam

print "\nSEARCHING...\n";

open (FILE, "security.txt");

print "\n";

###### Define names and their file paths ######

%exe = ( "Catalog", 'C:\Program Files\Internet Explorer\IEXPLORE.EXE',
"Crime", 'D:\crime\Reader\AcroRd32.exe');

###### Try to count the occurance of file paths ######

$count=0;

while(<FILE>) {

chomp;

  #if ($_ = (values %exe)) {
        $count++;
}

###### print names and counts #######

foreach $key (keys %exe) {

print "Name: $key\t Count: $count\n";

}

print "\nDONE.\n";

close(FILE);



Relevant Pages

  • Re: can I replace a string in all Matlab .m files under a folder?
    ... How to write a program in Matlab to change the strings ... maybe the Perl in Matlab can help? ... the command that follows is to be executed. ...
    (comp.soft-sys.matlab)
  • Re: can I replace a string in all Matlab .m files under a folder?
    ... How to write a program in Matlab to change the strings ... maybe the Perl in Matlab can help? ... the command that follows is to be executed. ...
    (comp.soft-sys.matlab)
  • Re: Math
    ... converting them to strings, then back, the precision will be lost. ... following instructions from perl. ... involve steps performed by the C compiler. ...
    (comp.lang.perl.misc)
  • Re: Regex: Why is overreaching necessary?
    ... SJ> Dealing with an array of fixed length strings. ... even good perl hackers ... is the search value something with alternation as the ... in fact as you have been told, substr and a hash lookup might be the ...
    (comp.lang.perl.misc)
  • Re: [Regex] Suchen nach Hex-Zeichen
    ... daher muss Perl wissen, in welchem Zeichensatz das Script abgespeichert ... allen Strings klarkommt, in denen nur Zeichen bis 0xFF vorkommen, solange ... man Strings als Zeichenfolgen betrachtet und nicht die Plattform wechselt. ... besteht der aus einem Zeichen mit dem Code 0x84. ...
    (de.comp.lang.perl.misc)