http://qs1969.pair.com?node_id=11135479

NERDVANA has asked for the wisdom of the Perl Monks concerning the following question:

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];