This doesn't explain your error message, but it does highlight a couple of problems with your code that could be a contributory factors.
#! perl -w use strict; my $args = { src=>'commit' }; if ($args->{err}) { print "There is a problem : $args->{err}\n"; } if ($args->{src} eq "commit") { print "I've got my sources!\n"; print "I'm committed!\n" if (!$args->{err}); } __END__ # Output C:\test>192192 I've got my sources! I'm committed!
You''ll notice that there is no key 'err' defined in the hash, and that, "I'm commited" was printed.
If I modify this as follows:
#! perl -w use strict; my $args = { src=>'commit' }; if ( exists $args->{err} && $args->{err} ) { print "There is a problem + : $args->{err}\n"; } if ($args->{src} eq "commit") { print "I've got my sources!\n"; print "I'm committed!\n" if (!exists $args->{err} && !$args->{err} +); } __END__ # Output C:\test>192192 I've got my sources!
This time, the "I'm commited" wasn't printed!
The reason for this is autovivifcation. Even testing for the presence of a hash element if you do it in any other way than using exists. Even doing if (defined $args->{key}) {...} will cause the key to 'spring into existance'.
Another clue to your error message is that coding if ($somevar) is semantically similar to doing if ( $somevar ne '' ) and the test is probably translated as such by the compiler.
Changing your code to use exists key && key may make your warning go away.
I did have a thought that if the reference being shifted into $args is a bless'd reference, the source of the warning might lie outside your code in the blessing package, but my knowledge of Perl's OO stuff is still in it's infancy, so I can't add anything to the thought.
In reply to Re: Use of uninitialized value in string
by BrowserUk
in thread Use of uninitialized value in string
by c
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |