in reply to count sort & output
test.pl: use hot_web; use strict; my $hot = new hot_web; $hot->count("www.yahoo.com","200"); #set to 200 $hot->count("www.yahoo.com","+20"); #add 200 $hot->count("www.yahoo.com"); #increase by 1 $hot->count("www.google.com","3000"); #set 20 3000 $hot->count("www.google.com","+300"); #add 300 $hot->display; hot_web.pm: package hot_web; use strict; sub new { my $self = {}; bless $self; return $self; } sub count { my $self = shift; my $url = shift; if (@_) { my $count = shift; if ($count =~ /^\+/) { $self->{$url} += $count; } else { $self->{$url} = $count; } } else { $self->{$url} ++; } } sub display { my $self = shift; print "Hot Webs:\n"; foreach (sort {$self->{$a} < $self->{$b}} keys %{$self}) { print "$_ appears: $self->{$_} time(s)\n"; } } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: count sort & output
by jdporter (Paladin) on Dec 19, 2002 at 03:29 UTC | |
|
Re^2: count sort & output
by Aristotle (Chancellor) on Dec 19, 2002 at 08:39 UTC |