Re: Help - Counting text - Associative Array?
From: Roel van der Steen (roel-perl_at_st2x.net)
Date: 03/19/04
- Previous message: Sam Lowry: "Help - Counting text - Associative Array?"
- In reply to: Sam Lowry: "Help - Counting text - Associative Array?"
- Next in thread: Sam Lowry: "Re: Help - Counting text - Associative Array?"
- Reply: Sam Lowry: "Re: Help - Counting text - Associative Array?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 19 Mar 2004 17:30:59 GMT
On Fri, 19 Mar 2004 at 16:59 GMT, Sam Lowry <mr_lowry@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
- Previous message: Sam Lowry: "Help - Counting text - Associative Array?"
- In reply to: Sam Lowry: "Help - Counting text - Associative Array?"
- Next in thread: Sam Lowry: "Re: Help - Counting text - Associative Array?"
- Reply: Sam Lowry: "Re: Help - Counting text - Associative Array?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|