Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


What's this about a "crooked mitre"? I'm good at woodwork!

In reply to Re: Use of uninitialized value in string by BrowserUk
in thread Use of uninitialized value in string by c

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 02:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found