in reply to hashes with multiple keys

It will not work with this data. For example in the volume_output table, vol2 refers to which host? There are two vol2 (one on host1 and one on host2). Are they different or are they the same vol2?

If you want to solve your problem with a hash or --more likely-- a hash of hashes, your keys must be unique.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: hashes with multiple keys
by annie06 (Acolyte) on Feb 27, 2009 at 21:12 UTC
    that is the problem, the same volume can exist on multiple hosts. Any ideas of what direction to go since hash won't work?
      Do you mean "a volume with the same name can exist on different hosts"?

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        countzero, I rather think annie06 does mean that - a volume has only to be unique on a specific host - thus volumes having the same name can legitimately exist on one, or more, different hosts.

        This applies to all OSes, even (tho' it pains me greatly to say it) Windoze - every Windoze host has a C: drive, which, in this context, can be taken to be the equivalent of a volume name.

        IMO. the question (to ask of annie06) ought to be: 'Are all volumes the same size on every host?'

        My reading of the OP suggests that where ever i.e. on which ever host, vol2 exists, it is always 20g, so a simplified version of the lookup table based approach (similar to that outlined by kennethk) should suffice - something along the lines of i.e. untested ...

        use warnings; use strict; use autodie; #for each vol_size_entry in the volsize file do # add the vol_size_entry to the volsize lookup (keyed on vol name) #done open FILE, "<volsize"; my %volsize = map { local @_ = split; # $_[1] needs normalising (to chosen common units) and removal of +unit spec /_name/ ? () : ($_[0] => $_[1]); } <FILE>; close FILE; #for each host_entry do # lookup the size of the vol for the host # add the vol size to the record for the host #done open FILE, "<hostfile"; my %hostsize; while (<FILE>) { next if /_name/; local @_ = split; $hostsize{$_[1]} += $volsize{$_[0]}; } close FILE;

        A user level that continues to overstate my experience :-))