When troubleshooting OLE issues, it is best to have the following code
after each OLE command...
If (Win32::OLE->LastError() != 0) {
print "error calling blah: " . Win32::OLE->LastError() . "\n";
exit 0;
}
...Or something similar, so you can see what OLE had issues with (if
anything). It might lead you in a direction that fixes it.
Steven
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On
> Behalf Of Michael
> Sent: Thursday, December 03, 2009 6:19 AM
> To: [email protected]
> Subject: RE: WIN32::OLE WMI Out params
>
> > Michael <> wrote:
> >> Hi,
> >>
> >> I'm a novice regarding Perl, and need some help converting a
> >> VBScript to a PerlScript.
> >>
> >> The following VBScript returns some data from HP OpenView. The
> >> GetChildNodeGroups method returns the number of ChildGroups,
> >>
> >> and the [out] parameter NodeGroups returns an array which
> contains a
> >> list of OV_NodeGroup.
> >>
> >> > From the documentation:
> >>
> >> sint32 GetChildNodeGroups(
> >> [out] OV_NodeGroup NodeGroups[],
> >> [in, optional] boolean IncludeSubGroups)
> >>
> >> Description
> >> Returns a list of node groups (instances of OV_NodeGroup)
> that are
> >> children of this node group.
> >>
> >> Return Value
> >> Number of node groups (children) in the out parameter NodeGroups.
> >>
> >> ' VBScript Begin
> >>
> >> Option Explicit
> >>
> >> Dim objWMIService, objOV_NodeGroup, objGetRoot, objChildGroups,
> >> arrNodes, objItem
> >>
> >> Set objWMIService =
> >> GetObject("winmgmts:root\HewlettPackard\OpenView\data")
> >>
> >> Set objOV_NodeGroup = objWMIService.Get("OV_NodeGroup") Set
> >> objGetRoot = objOV_NodeGroup.GetRoot() objChildGroups =
> >> objGetRoot.GetChildNodeGroups(arrNodes, True)
> >>
> >> WScript.Echo "Child Group Count: " & objChildGroups & vbCrLF
> >>
> >> For Each objItem In arrNodes
> >> WScript.Echo "Name: " & objItem.Name Next
> >>
> >> ' VBScript End
> >>
> >> The problem is that I can't find out how to get the array
> >> (@arrNodes) in Perl.
> >>
> >> # PerlScript Begin
> >> use strict;
> >> use warnings;
> >> use Win32::OLE qw(in with);
> >> use Data::Dumper;
> >>
> >> my $objWMIService =
> >>
> Win32::OLE->GetObject("winmgmts:root/HewlettPackard/OpenView/data")
> >> or die "WMI connection failed.\n"; my $objOV_NodeGroup =
> >> $objWMIService->Get("OV_NodeGroup"); my $objGetRoot =
> >> $objOV_NodeGroup->GetRoot();
> >>
> >> my @arrNodes;
> >>
> >> my $objChildGroups = $objGetRoot->GetChildNodeGroups("@arrNodes",
> >> "True");
> >
> > And you were doing so well up to this point. I really don't
> think that
> > you want to pass an empty array, interpolated into a string, as an
> > output parameter. In fact, I would expect that it might
> even produce a
> > run-time error. Does it?
>
> Nope it does not. The problem is still that @arrNodes is
> empty. The GetChildNodeGroups method does not populate the
> variable/array like it does in VBScript. Therefore I've been
> around "@arrNodes", \...@arrnodes, $nodes etc...
>
> >
> > I don't know the answer, but from my limited Perl/OLE
> experience, my
> > first guess would be that the function would want to return an OLE
> > container object in the output parameter, and so would
> expect it to be
> > a reference to a scalar. For example:
> >
> > my $nodes;
> > use constant TRUE => 1;
> > my $objChildGroups = $objGetRoot->
> GetChildNodeGroups(\$nodes, TRUE);
> >
> >>
> >> print "Child Group Count: " . $objChildGroups . "\n";
> >>
> >> print @arrNodes . "\n";
> >
> > If I am right, and I may well not be, this would probably
> need to be
> > something like:
> >
> > for my $obj (in $nodes) {
> > print "Name: $obj-> {Name}\n";
> > }
> >
>
> Yep - but because $nodes/@arrNodes is empty this does not change much.
>
> >>
> >> # PerlScript End
> >>
> >> Any help would be appreciated.
> >
> > HTH, in lieu of somebody coming up with a more certain answer.
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs