CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Reference or not?

 



jolt
Deleted

Jul 30, 2000, 3:11 PM

Post #1 of 2 (282 views)
Reference or not? Can't Post

I'm using perl to generate reports.
Each line contains a hostname and size field
I can view hostnames and how many times that host has requested something.
However I'd like to add the total size amount of all the hosts' requests. How do I do this?
I've tried to use the following with no success:
#Count hosts (works)
$hash{$host}++
#Count size per host (doesn't work)
$hash{host}->{$size}++

/Thanks!


Kanji
User

Jul 31, 2000, 3:16 PM

Post #2 of 2 (282 views)
Re: Reference or not? [In reply to] Can't Post

Use a hash of hashes ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$hash{ $host }{'count'}++;
$hash{ $host }{'size'} += $size;

# ... do schtuff ...

for my $key ( sort keys %hash ) {
print join "\n " =>
$key,
"$hash{ $key }{'count'} requests ",
"totaling $hash{ $key }{'size'}K".
}</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives