2

I've been trying to do this for a while and I just can't seem to understand the vCLI SDK. I believe the MO that I want to use is ServiceContent->Task Manager, then print out the recent task. Here is my subroutine for doing it:

sub TaskManager {
    my $begin;
    my $mor = Vim::get_service_content()->taskManager;
    my $taskmanager_view = Vim::get_view(mo_ref => $mor);

    my $my_filterSpec = TaskFilterSpec->new();
    my $eventArray = $taskmanager_view->CreateCollectorForTasks(filter => $my_filterSpec);
    foreach (@$eventArray) {
        # my $collector_view = Vim::get_view(mo_ref => $eventArray);
        print $_->recentTask . "\n";
    }
}

When I run this I either get:

Not an ARRAY reference at ./TaskManager.pl line 43.

When I change this, I then get:

subroutine &ManagedObjectReference::recentTask called at ./TaskManager.pl line 45

Here's one of the DOCS I've been looking at

https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.TaskManager.html

I also have some conversations happening here: https://www.reddit.com/r/vmware/comments/4qfaql/help_with_vcli_perl_script/


EDIT: I changed my subroutine to the following:

sub TaskManager {
    my $begin;
    my $mor = Vim::get_service_content()->taskManager;
    my $taskmanager_view = Vim::get_view(mo_ref => $mor);
    my $my_filterSpec = TaskFilterSpec->new();
    my $eventArray = $taskmanager_view->CreateCollectorForTasks(filter => $my_filterSpec);
    foreach ($eventArray) {
        my $newRecentTask = $taskmanager_view->description;
        print $newRecentTask . "\n";
    }
}

But the problem is that the print statement is returning a hash value, not something I can use. Any ideas how to get something readable?

callyalater
  • 3,102
  • 8
  • 20
  • 27
  • When you changed your `foreach (@$eventArray) {...}` loop to `foreach ($eventArray) {...}`, you changed it to iterate over a *reference* (Remember that the `$` sigil is for scalars). In fact, your new code doesn't use `$eventArray` at all (either through an explicit iterating variable or implicitly through `$_`). Subroutines in Perl (and other scripting languages like Ruby) implicitly return the last evaluated statement (which is `print` in this case, as you correctly guessed). – callyalater Jun 29 '16 at 15:34
  • So is that the reason why i'm getting a hash returned when I run it? – egkennedy93 Jun 29 '16 at 15:48
  • Probably not. At least, not entirely. It is probably because `description` is an object, not a simple string ([see this](https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.TaskDescription.html)). – callyalater Jun 29 '16 at 15:52

0 Answers0