Hi there!

I've skimmed the posting rules beforehand but this is my very first post here so excuse me if there is any mistake in my interpretation of them.

I've already posted this question in another Perl related forum without success and PerlMonks has eventually been pointed out.

I have the following snippet of code (the code is not as pedantic as I'd like it to be, but it's not mine and I'll dump it as-is in case I've overlooked something):

18: sub getPasswordStatus { 18: my ($login, $password) = @_; 20: my$quotedLogin = quotemeta($login); 21: my $Passwd; 22: 23: if( $password && $password !~ /\?{7,7}/ ) { 24: if ($password =~ m/^NO PASSWORD$/i){ 25: $Passwd = 'empty'; 26: } elsif ($password =~ /^PASSWORD$/i){ 27: $Passwd = 'password'; 28: } elsif ($password =~ /^$quotedLogin$/i){ 29: $Passwd = 'login'; 30: } else { 31: $Passwd = 'weak'; 32: } 33: } else { 34: $Passwd = 'ok'; 35: } 36: return $Passwd; 37: }

As you can see, this is not a very tricky piece of code. But I have a very weird behaviour though. For some passwords, I get the following message:

        Use of uninitialized value in string eq at lib/Pwc/Policy.pm line 24.

It's worth noting that it always happens for the same 7 or 8 passwords among more than 20000. Interestingly, the guilty passwords don't seem to differ from the others. All I can say is they are always using the same scheme: an upper case letter, then a few lower case letters and finally some numbers. But this doesn't mean that passwords matching this scheme will trigger the warning! For instance the password "Alcatel1" generates an error but the password "Algerie1" doesn't.

Even more interestingly, the error is only generated for the first test line 24, not for the others on line 26 and 28, although the passwords causing this error obviously don't match the first test and thus should go through the others.

I tried to change the test on line 23 to

if( defined $password && $password !~ /\?{7,7}/ )
but it doesn't change anything and it shouldn't actually because if $password is undefined, then "$password" is false, and we don't enter in the guilty block.

I've also tried to change the regular expression match to a simple eq, but I have the exact same behaviour.

I've printed the passwords in hexadecimal in case there would be non-printable characters, but there isn't. But hey! How could I print the password if it is undefined? It's crazy, isn't it?

I'm really puzzled on this bug. My leaning goes toward a Perl bug... Any idea to prove me I'm wrong?

For what it's worth, this error happens on ActivePerl:

        This is perl, v5.8.8 built for MSWin32-x86-multi-thread

Thank you very much for you help.

Best regards,


In reply to Puzzling warning "Use of unitialized value" in very simple code by jlhsgcib

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.