What is the effect of the statement
@wrongPasswords[4] = ();
on the array? If the array is dumped immediately after this statement (see Data::Dump::dd), what is its content? Why? (If this statement is run with warnings asserted, what will Perl say about the statement?)
Does the push built-in have any effect on elements already in an array to which a new element is push-ed?
If a Data::Dump::dd statement for the @wrongPasswords array is inserted immediately before the
print"@wrongPasswords\n";
statement, what is the content of the array, and why?
c:\@Work\Perl>perl -le "use Data::Dump qw(dd); ;; $password = 'perlclass'; print qq{What is the password to access the system\n}; $count = 0; @wrongPasswords[4] = (); dd \@wrongPasswords; ;; while($guess ne $password && $count != 4 ){ $guess = <stdin>; chomp($guess); if($guess eq $password){ print qq{You have unlocked the program\n}; } else { push(@wrongPasswords,$guess); if($count != 3){ print qq{Sorry wrong choice! Try again\n}; } else{ print qq{\nYou have enter too many passwords!\nProgram Locked!! +\n}; print qq{Here are the passwords that were entered\n}; dd \@wrongPasswords; ;; print qq{@wrongPasswords\n}; } } $count++; }; print 'pause...'; " What is the password to access the system [undef, undef, undef, undef, undef] foo Sorry wrong choice! Try again bar Sorry wrong choice! Try again baz Sorry wrong choice! Try again boff You have enter too many passwords! Program Locked!! Here are the passwords that were entered [undef, undef, undef, undef, undef, "foo", "bar", "baz", "boff"] foo bar baz boff pause...
Update: This is a very belated afterthought, but it occurs to me that because programmercarlito is clearly a novice and I have no idea of his or her ability to install modules, I should rather have used Data::Dumper, which is core, in the example and not Data::Dump, which is not core.
So the use statement could be
use Data::Dumper;
and the invocations would be
print Dumper \@wrongPasswords;
rather than
dd \@wrongPasswords;
Give a man a fish: <%-(-(-(-<
In reply to Re: Password Program
by AnomalousMonk
in thread Password Program
by programmercarlito
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |