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;
In reply to Re: count sort & output
by pg
in thread count sort & output
by mkent
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |