I need to get the cloud.uuid (or any other optionValue for that matter) from the extraConfig data object. Is there a way to get to the value of a specific key without having to iterating through the array? As this is not a hash, attempt at getting to the value with this fails miserably:
$extra->{'could.uuid'}...
Here is an iteration approach that works.
my $extra = $vm->config->extraConfig;
foreach (@$extra) {
print $_->value if ($_->key =~ /cloud.uuid/);
}
Thanks!
Unfortunately it's an array, so you'll have to iterate. If you wanted to, you could convert it to a hash.
You could use 'grep' as well to get a one liner. It won't be such a large array in any event that there is any real dramatic speed increase between a hash and an array.
Thanks stumpr. Understood. Just wanted to see if anything magic out there...
You can use config.extraConfig["cloud.uuid"] as the property name in PropertySpec pathset and that will retrieve only the cloud.uuid extraconfig.
Within perl you can do the following to find an element in an array:
if (grep {$_ eq $element} @TheArray) { print "Element '$element' found!\n" ; }
(Original article here How to find out if X is an element in an array? )
You can adapt this to your scenario by doing:
print $_->value if (grep {$_->key =~ /cloud.uuid/} @$extra);