in reply to How to check that keys in two hashes match and get the corresponding values
This code uses a small hack providing itself a fake hash and hash key when '%filer_device' value is not a hash reference. The downside of it is lack of data structure checking, so the real solution should be more verbose (and probably use Params::Validate, Data::Validator, Data::Diver or Data::DPath).while (my ($name, $hash) = each %nfs) { for my $devloc (ref $hash->{'%filer_device'} ? keys %{$hash->{'%fi +ler_device'}} : '%filer_device') { # hack here my $device = (ref $hash->{'%filer_device'} ? $hash->{'%filer_d +evice'} : $hash)->{$devloc}; # and here my $volume = ref $hash->{'%filer_volume'} ? $hash->{'%filer_vo +lume'}{$devloc} : $hash->{'%filer_volume'}; print "\@dev $name $device $volume $hash->{'%export_name'}\n"; } }
|
|---|