in reply to hashes with multiple keys
Given that your provided host_output file shows a many-to-many mapping, the choice on that front would seem to be a hash of arrays (perllol), keyed on whichever value you'll want as your primary (I'm guessing host). The second half is easier, as your volume content can be stored in a simple hash. You could calculate the host size something like this:
use strict; use warnings; my %volume = (host1 => ['vol1', 'vol2', 'vol3' ], host2 => ['vol4', 'vol5', 'vol2' ], ); my %size = (vol1 => 10, vol2 => 20, vol3 => 30, vol4 => 30, vol5 => 20, ); my $host = 'host1'; my $total_size = 0; foreach my $vol (@{$volume{$host}}) { $total_size += $size{$vol}; } print "$host has $total_size at it's disposal.\n"
Update: Forgot a doc tag in my perllol link, so linked to the wrong documentation. Oops and fixed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: hashes with multiple keys
by annie06 (Acolyte) on Feb 27, 2009 at 21:52 UTC | |
by kennethk (Abbot) on Feb 27, 2009 at 22:00 UTC | |
by annie06 (Acolyte) on Feb 27, 2009 at 21:53 UTC |