Perl knows about a lot of posix character classes because you can match against them with the regex library. But what if you want to reverse that? I would like to iterate the characters that belong to a named character class, and take advantage of Perl's knowledge rather than building massive lists of my own. I would also like to avoid brute-force solutions like iterating every character and testing each for membership in the set.

Does anyone know if there is a good way to do this? Ideally quick enough to look up random members of the set in log(n) time or better.

Example of a Not-Good way to do this:

my @alpha= grep /[[:alpha:]]/, map chr, 0..0xEFFFF; return $alpha[rand scalar @alpha];

In reply to Inspect the members of a Posix Character Class by NERDVANA

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":