Welcome! Here's how you can figure out this problem - and many others! - yourself:

Once you've done that, have a look at @wrongPasswords with Data::Dumper, as described in the Basic debugging checklist item 4. You will see that it looks something like this:

$VAR1 = [undef, undef, undef, undef, undef, "one", "two", "three", "four"];

What is going on here is that the line @wrongPasswords[4] = (); isn't quite right. You're probably trying to say "initialize the array @wrongPasswords to a size of four", but that's not necessary as Perl has dynamically sized arrays (kind of like a vector in C++). Instead, in Perl, @wrongPasswords[4] is what is known as an array slice, and you're telling Perl you want to write an empty list to the index 4 of the array, so to do that, Perl automatically sizes your array to five elements and initializes them to undef (a little bit like NULL). In your loop you use push, which adds elements to the end of the array. So when you say print "@wrongPasswords\n";, what you're seeing is five empty strings (the undefs) separated by spaces, followed by the rest of the items of the array. In this case, to set up @wrongPasswords, all you need to do is write my @wrongPasswords;.


In reply to Re: Password Program by Anonymous Monk
in thread Password Program by programmercarlito

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.