a couple things of note is that
/(\w{2,16})/ will not check to see if the
$username is between 3 and 16 letters and numbers. The fact that the lower limit is 2 will allow anything that is at least 2 characters. Also the fact that you have 16 in there doesn't do much more than tell the regex not to match more than 16
\w chars in a row. To put it another way it will match the most left hand match that is at least 2 characters long (in the character class
[A-Za-z0-9_]) and will then try to match up to 16 characters (and this will be stashed into
$1) Which might not be what you want as then anything over 16 characters will be truncated off when you replace the value in
$username with
$1. And as I already mentioned
\w will match letters number and underscore (which does not fit your criteria) You might be looking for something more along these lines.
...
if ( $username =~ /\A([A-Z0-9]{3,16})\z/i ) {
$username = lc($1);
}
else { ... }
Lastly if you are not going to capture what is output by the command you should use
system instead of backticks (though you should probably capture what is returned by system anyhow) .
Note: that
$username will have to be chomped (have the newline removed) or
\z won't match, in which case changing
\z for
$ will do just as well.
One last thing is that you should really go through perlre and perlretut as they contain invaluable information.
-enlil
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.