Help - Counting text - Associative Array?
From: Sam Lowry (mr_lowry_at_hotmail.com)
Date: 03/19/04
- Next message: Roel van der Steen: "Re: Help - Counting text - Associative Array?"
- Previous message: R D: "What directory perl script is being run from? - followup"
- Next in thread: Roel van der Steen: "Re: Help - Counting text - Associative Array?"
- Reply: Roel van der Steen: "Re: Help - Counting text - Associative Array?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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);
- Next message: Roel van der Steen: "Re: Help - Counting text - Associative Array?"
- Previous message: R D: "What directory perl script is being run from? - followup"
- Next in thread: Roel van der Steen: "Re: Help - Counting text - Associative Array?"
- Reply: Roel van der Steen: "Re: Help - Counting text - Associative Array?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|