size must eqaul to 8

OK for learning, bad for production code. Don't limit the password length, it that makes passwords weak. See also https://xkcd.com/936/. Of course, you may want to prevent short passwords, i.e. require a minimum length (8 chars minimum, more required when computers get faster).

Also, you don't want to hardcode a password, or store it in plain text somewhere. State of the art is to use a salted hash (google it), i.e. generate a short random string (the salt), put original password and salt into a strong hash function, store salt and hash value. To verify an entered password, reuse the salt, put entered password and salt into the same hash function, and verify that the new hash value matches the stored hash value.

Regarding your code, there is no need to split the input into an array. Use length to get the number of characters in a string. Also, you may want to use chomp on your input to remove the trailing newline.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: How can I use all special characters in perl by afoken
in thread How can I use all special characters in perl by Ekanvitha9

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.