Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

unable to resolve warning "Use of uninitialized value in ..."

by lepetitalbert (Abbot)
on Oct 24, 2005 at 13:49 UTC ( #502465=perlquestion: print w/replies, xml ) Need Help??

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 (Pope) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://502465]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2020-10-25 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?