Roel van der Steen <ro*******@st2x.net> wrote in message news:<sl**********************@localhost.localdoma in>...
On Fri, 19 Mar 2004 at 16:59 GMT, Sam Lowry <mr******@hotmail.com> wrote: direction.
I want to count several strings of text in a file (security.txt) and
output the counts with a brief description of each.
<OP's attempt snipped>
Not too bad after all. But this works:
#!/usr/bin/perl
use strict;
use warnings;
print "\nSEARCHING...\n\n";
my %exe = (
'C:\Program Files\Internet Explorer\IEXPLORE.EXE' => 'Catalog',
'D:\crime\Reader\AcroRd32.exe' => 'Crime',
);
my %count;
open (FILE, "security.txt");
while (<FILE>) {
chomp;
$count{$_}++ if exists $exe{$_};
}
close FILE;
print "Name: $exe{$_}\t Count: $count{$_}\n" foreach sort keys %exe;
print "\nDONE.\n";
__END__
security.txt would need to contain something like:
C:\Program Files\Internet Explorer\IEXPLORE.EXE
D:\crime\Reader\AcroRd32.exe
D:\crime\Reader\AcroRd32.exe
D:\crime\Reader\AcroRd32.exe
Dear Mr. van der Steen,
Thank you for your kind reply. Unfortunately, the strings are not
alone on their own lines in security.txt. I should have posted a
sample, thus:
3/15/2004,3:01:18 PM,Security,Success Audit,Object Access ,560,SERVER\
+refterm,SERVER,"Object Open:
Object Server: Security
Object Type: File
Object Name: C:\Program Files\Internet Explorer\IEXPLORE.EXE
New Handle ID: 536
Operation ID: {0,178316546}
3/15/2004,1:57:28 PM,Security,Success Audit,Object Access ,560,SERVER\
+Anon000,SERVER,"Object Open:
Object Server: Security
Object Type: File
Object Name: D:\crime\Reader\AcroRd32.exe
New Handle ID: 592
Operation ID: {0,177426959}
Your code shows me the logic and syntax, and I will study it to make
sure I understand what you did. The problem now is how to see the
array values in security.txt? Do I need to use regex or index
(mentioned elsewhere but which I know nothing about)?
- I just realized something: The context of the strings in
security.txt is always the same:
Object Name:[uniform space]$exe
If I include 'Object Name: ' with the C:\... as the complete value
in the array of my script it should work, no? Not the most elegant
solution but my eyes are already crossed after working on this having
had no formal training with Perl.
What is <the right way> to do this?
Thanks for reading.
Sam