From: [EMAIL PROTECTED]
> 
> 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 } 
> 
> $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? 

Without knowing the exact structure of $services, I can make a guess based
on your syntax.

If DisplayName returns an array, do this:
    push( @ary, $services->[$j]->DisplayName );

If DisplayName returns an array reference, do this:
    push( @ary, @{$services->[$j]->DisplayName} );

Explanation...

$services is a reference to an array, so you have to dereference it one of
two (or maybe more) ways to get an element:
    $$services[$j]
  or
    $services->[$j]

I prefer the second method since it is a bit clearer.

Now call the DisplayName method:
    $services->[$j]->DisplayName

If DisplayName returns an array, we can push it as is.

Otherwise, we need to dereference it to get the array
    @{$services->[$j]->DisplayName}

And then pushing it onto your array variable completes the process.

Bowie
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to