Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Re: count string occurance

by PrakashK (Pilgrim)
on Jul 27, 2001 at 22:58 UTC ( #100415=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: count string occurance
in thread count string occurance

In that case, you'd read the names from file as you were doing in your own example. And do the counting while your are reading the file itself.

while (<FILE>) { ## extract NAME from the record ## count it $names{$name}++; }


Comment on Re: Re: Re: count string occurance
Download Code
Re: Re: Re: Re: count string occurance
by softworkz (Monk) on Aug 01, 2001 at 17:11 UTC
    Thanks a bunch guys, this is what I decided to go with.
    #!/usr/bin/perl -w use win32; use strict; %hash = (); my $user_usage = $in_file."_user_usage.txt"; open(FILE,"$dups") || die "user_time.pl can't open: $!"; open(USERTIME,">$user_usage") || die "user_time.pl can't open: $!"; # Define the output file format our $UserID="UserID"; our $days="Usage"; format USERTIME= @<<<<<<<<<<<<<@>>>>>>> $UserID, $days . #write the title line write(USERTIME); my $user; my $time; my $date; my $node; while (<FILE>) { chomp; next unless ( ($_ =~ /$in_year/) ); ($user, $node, $date) = split; push(@{$hash{$user." ".$date}}, $node); } foreach $user(sort keys %hash ) { $time = @{$hash{$user}++}; #print $user, " ", $time, "\n"; print USERTIME $user, " ", $time, "\n"; } close FILE; close USERTIME;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://100415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2015-03-31 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:









    Results (663 votes), past polls