ScooterTrash has asked for the wisdom of the Perl Monks concerning the following question:
I am converting some VB scripts to perl and I am having a problem referencing instances of an object that are returned in a method. The first code below is the VB code and the second is the perl code.
The problem is the value in $NGList is the number of instances returned not a list of the object instances like I thought it would be. The in the foreach loop the value of 4 (the number of instances returned) is assigned to $fNode. The assignment of $objNodes in the ExecQuery works fine and the line print "$fNode->{PrimaryNodeName}\n"; works fine. Any suggestions?
VB Script
Set WshNetwork = WScript.CreateObject("WScript.Network") Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objSWbemLocator.ConnectServer(strMLM,"\root\hewlet +tpackard\openview\data") Set objNodes = objWMIService.ExecQuery("select * from OV_ManagedNode w +here PrimaryNodeName like '" & strND & "%'") for each nm in objNodes Wscript.Echo "Primary Node name is " & nm.PrimaryNodeName '& vbNew +Line Name = nm.name nm.GetParents(NGarray) For Each gp in NGarray Wscript.Echo gp.Caption Next next Wscript.Quit 0
Perl Script
$objSWbemLocator = Win32::OLE->new("WbemScripting.SWbemLocator"); $objWMIService = $objSWbemLocator->ConnectServer($strMLM,"\\root\\hewl +ettpackard\\openview\\data"); $objNodes = $objWMIService->ExecQuery("Select * from OV_ManagedNode wh +ere PrimaryNodeName like \"%$argNode%\""); foreach $fNode (in $objNodes) { print "$fNode->{PrimaryNodeName}\n"; $NGList = $fNode->GetParents() or die; foreach $fNode ($NGList) { print "***************\n"; my $fName = $fNode->{Name}; my $fCaption = $fNode->{Caption}; print "$fName:$fCaption \n"; #GUID of the group @polGrps = $fNode->GetAutoDeployPolicyGroups; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with win32 objects
by runrig (Abbot) on Feb 25, 2011 at 01:46 UTC | |
|
Re: Problem with win32 objects
by toolic (Bishop) on Feb 25, 2011 at 01:50 UTC | |
|
Re: Problem with win32 objects
by ScooterTrash (Novice) on Feb 28, 2011 at 15:44 UTC |