in reply to Password Program
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;.
|
|---|