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
    thanks but how can I do that without hardcoding the volume name and size? Meaning my output is hundreds of lines that and I wnat to be able to run it against other files with similar output but different values.
      Based on your initial post, I assume you are already comfortable with file I/O. In order to generate your volume hash, you just need to start by putting an anonymous array in each hash entry and then populate it with a series of pushes. There are some reasonable examples in perllol.
      to be clear, I meant that I want my perl script to step through the output and build this list for me.