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; } }

In reply to Problem with win32 objects by ScooterTrash

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.