softworkz has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use win32; use strict; open(FILE,"chargenode.txt") || die "user.pl can't open writing: $!"; while (<FILE>) { #chomp; my @names; my $match; my $count; my $total; my $item; my @x; my ($name) = /(\w+\d+)/; push @names, $name; # if (m/.*\Hm54/) { # $count++; # # my $total = $count + $count; # } #$count += $_ for @names; # sample input: # UserID Date # Hm54 ATHENA02 10/1/2000 # Dh60 ATHENA02 10/1/2000 # Dh60 ATHENA02 10/2/2000 # Jch6 ATHENA05 10/2/2000 # Hh24 ATHENA05 10/2/2000 # Mwm22 ATHENA03 10/2/2000 $match = "Hm54"; foreach my $user (@names) { if ($match eq $user) { push @x, $item; } foreach $item (@x) { $count++; $total = $count; print "saw $name $total times \n"; } } #foreach } #while close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: count string occurance
by rob_au (Abbot) on Jul 27, 2001 at 20:10 UTC | |
by softworkz (Monk) on Jul 27, 2001 at 22:43 UTC | |
by PrakashK (Pilgrim) on Jul 27, 2001 at 22:58 UTC | |
by softworkz (Monk) on Aug 01, 2001 at 17:11 UTC |