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

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.