Omitting Optional Arguments in Method Calls

When you call a vSphere API method by using vSphere SDK for Perl, and want to omit an optional argument, you can do one of two things.
  • You can omit the argument.
    $vm->PowerOnVM(host => $host); # with the optional host argument $vm->PowerOnVM(); # without the optional host argument
  • You can supply
    undef
    as the value of the optional argument.
    $vm->PowerOnVM(host => undef);
Supplying
undef
as the value of the optional argument is useful when the value of an argument, which might or might not be
undef
, is contained in a variable, as in the following example.
my $host = Vim::find_entity_view( view_type => 'HostSystem', filter => { name => 'preferredHost' } ); $vm->PowerOnVM(host => $host);
You cannot use the empty string or the value 0 to represent
undef
or an unset parameter.