In addition to the good answer about ord above, you also need to realize that m/[55-90]/ isn't doing what you want. A bracketed construct matches exactly one character, one of the ones in its range. For example, m/[78!]/ would match any of the characters 7, 8 or !, but not the whole string 78!. Similarly, m/[5-9]/ would match any one of the characters 5, 6, 7, 8, or 9, but a construct like m/[55-90]/ is just confusing.

If you want to check whether the character is ascii, you need to see if it's within the range you want. Perl lets you check the character directly, like so:

if ($character >= 'A' && $character <= 'Z')
is a reasonable test, as long as you're sure your input is ASCII (it wouldn't work for EBCDIC, as an extreme example).


In reply to Re: Matching alphanumeric characters from urandom by VSarkiss
in thread Matching alphanumeric characters from urandom by Garanixx

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.