[EMAIL PROTECTED] wrote:

> 
> Wizards,
> 
> I'm doing something wrong here, but the complicated syntax is only
> confusing me.  Here's the code...
> 
> 45 my $services = $objWMIService->ExecQuery( "Select *
> 46                                               From Win32_Service
> 47                                               Where ServiceType =
> '$stype'" );
> 48
> 49 for my $j (0 .. [EMAIL PROTECTED]) {
> 50    push( @ary, @{$services}[$j]->DisplayName );
> 51 }

ALWAYS make a complete test case so we don't have to dick around with it.
Here's what you should have submitted (or something close) :

use strict;
use warnings;
use Win32::OLE qw(in);

my $WMI = Win32::OLE->GetObject("WinMgmts://$ENV{COMPUTERNAME}/root/cimv2") or
  die "GetObject: $!($^E)";

my $stype = 'Own Process';

my $services = $WMI->ExecQuery(
  "Select * From Win32_Service Where ServiceType = '$stype'");

# normal method using 'in' iterator

my @ary;
for my $obj (in $services) {
        push @ary, $obj->DisplayName;
}
print $_, "\n" foreach @ary;

__END__

> $services is the return from the ExecQuery call, and I'm trying to slap
> the DisplayName properties from it into an array. The syntax error "Not
> an ARRAY reference" pops up at the for loop line (line #49). As you can
> no doubt tell from the plethora of gobbledegook surrounding the terminal
> value, I'm (again) in over my pointy little head. Can someone help me
> straighten out the slapdash, throw-stuff-at-it-til-it-works, mess I've
> made of things?
> 
> I've got a working version, using the in operator, but this is the only
> code in a largish module that uses it, so if I can straighten this out,
> then I don't need to "use" in, and I can decrease the code's footprint.

# you can bypass the 'in' iterator with the All method :

my @ar1 = Win32::OLE::Enum->All($services);

my @ary;
foreach my $obj (@ar1) {

        # and use 'valof' to get the value
#       my $val = valof ($obj->DisplayName);

        # or try without valof (which should work in your case)
        my $val = $obj->{DisplayName};

        push @ary, $val;
}
print $_, "\n" foreach @ary;


-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to