Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
So far I have only been able to find bits and pieces on this and 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:
Yes I am a newb, so if anyone can point me in the right direction I'd sure appreciate it. TIA, SamName: Catalog Count:2 Name: Crime Count:1
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"; } close(FILE); print "\nDONE.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help - Counting text - Associative Array?
by matija (Priest) on Mar 19, 2004 at 18:46 UTC | |
by Mr_Lowry (Initiate) on Mar 19, 2004 at 20:32 UTC | |
|
Re: Help - Counting text - Associative Array?
by dragonchild (Archbishop) on Mar 19, 2004 at 18:43 UTC | |
|
Re: Help - Counting text - Associative Array?
by NetWallah (Canon) on Mar 19, 2004 at 18:46 UTC | |
|
Re: Help - Counting text - Associative Array? (I was Annon Monk)
by Mr_Lowry (Initiate) on Mar 19, 2004 at 19:25 UTC | |
by Not_a_Number (Prior) on Mar 19, 2004 at 20:27 UTC | |
by Mr_Lowry (Initiate) on Mar 19, 2004 at 20:48 UTC | |
by Hofmator (Curate) on Mar 22, 2004 at 14:16 UTC |