Accessing Enumeration
Property Values
To retrieve the value of a property defined
as an enumeration, you must dereference its value from within the containing
object by qualifying the property with
->val
.
For example, the power state of a virtual machine (powerState
)
is a member of the
runtime
data object.
To retrieve the value of
powerState
, you must dereference the two containing
objects (the
view
object and the
runtime
data object) and the value itself
(val
), as follows:
$vm_view->runtime->powerState->val
Because
powerState
is an enumeration, you use
runtime->powerState->val
to retrieve its string value.
foreach my $vm (@$vm_views) { if ($vm->runtime->powerState->val eq 'poweredOn') { print "Virtual machine " . $vm->name . " is powered on.\n"; } else { print "Virtual machine " . $vm->name . " is not powered on.\n"; }