in reply to Matching alphanumeric characters from urandom

Your pattern match, is matching:
5, 5-9 (5,6,7,8,9), and 0
Many characters will have chr values that match that. Try this:
if ($character =~ m/^[a-z0-9]$/) { ... }

Replies are listed 'Best First'.
Re^2: Matching alphanumeric characters from urandom
by dragonchild (Archbishop) on Feb 07, 2005 at 21:03 UTC
    Alternately, that can be rewritten as one of the following:
    • if ($character =~ /[a-z\d]/)
    • my %is_legal = map { $_ => ~~1 } 'a' .. 'z', 0 .. 9; if ($is_legal{ $character })
    • if ($character !~ /\W/ && $character ne '_' && lc $character eq $character)
    • if ($character =~ /\w/ && $character ne '_' && lc $character eq $character)

    (The latter two aren't really serious ...)

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.