lepetitalbert has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

can't get my way out the following :

$class = "winmgmts:{impersonationLevel=impersonate}\\\\$key\\Root\\c +imv2"; $process_info = Win32::OLE->GetObject( $class ) || warn "\n shit"; my $cnt = 0; foreach my $process ( sort { $a->{Name} cmp $b->{Name}} in( $process_info->InstancesOf( "Win32_Process" ))) { print LOG $process -> {Name} . "\n"; print LOG $process -> {ProcessID} . "\n"; print LOG $process -> {ExecutablePath} . "\n\n"; }

The thing is

$process -> {ExecutablePath}

can be empty (that causes the warning if I'm right). I can't test

if ( "" ne $process->{ExecutablePath} ) { ... }

cos warning again!

Hope someone can point out what am doing wrong.
Thanks

Have a nice day.

Replies are listed 'Best First'.
Re: unable to resolve warning "Use of uninitialized value in ..."
by Corion (Patriarch) on Oct 24, 2005 at 13:56 UTC

    The way to check for an undefined value in Perl is

    if (defined $value) { ... };

    (see perldoc -f defined for more information). You could also turn off the warning, but usually, turning off a warning is a bad practice because you're likely to forget to turn it on again immediately afterwards.

    { no warnings 'uninitialized'; print LOG $process->{ExecutablePath}, "\n"; };
Re: unable to resolve warning "Use of uninitialized value in ..."
by jhourcle (Prior) on Oct 24, 2005 at 13:58 UTC

    Blank is different from uninitialized ... try changing the test to:

    if ( not defined($process->{ExecutablePath} )) { ... }
Re: unable to resolve warning "Use of uninitialized value in ..."
by jesuashok (Curate) on Oct 24, 2005 at 14:25 UTC

    Hi ..

    if ( $process -> {ExecutablePath} ) { ...... Code Stuff .... }

    The above will become true ony if it contains any values. It becomes false for "",'' and undef.
    "Keep pouring your ideas"

      Hi again, problem solved :

      if ( defined $process -> {ExecutablePath} ) { print LOG $process -> {ExecutablePath} . "\n\n"; }

      Thanks
      Have a nice day.