Re: range operator vs. unicode

[email protected] (Dan Kogai)
Newsgroups perl.unicode,perl.perl5.porters
Message-ID <[email protected]>
On Jun 08, 2006, at 17:34 , Yitzchak Scott-Thoennes wrote:
> Which part should be fixed?

The limitation of the magic, namely....
>
> The key part is that magical auto-increment is defined earlier as
> only working for strings matching "/^[a-zA-Z]*[0-9]*\z/".

Which is described in "Auto-increment and Auto-decrement", though  
"Range Operator" does mention.

perldoc perlop
>        The range operator (in list context) makes use of the  
> magical auto-
>        increment algorithm if the operands are strings.

This would make lawyers happy enough but not (Uni)?coders like  
myself.  With the advent of Unicode support more people would attempt  
things like ("\N{alpha}" .. "\N{omega}") and wonder why it does not  
work like ("a".."z").  So we should add something like;

=head2 CAVEAT

Note that the range operator cannot apply magic beyond C<[a-zA-Z0-9] 
 >.  Therefore

   use charnames 'greek';
   my @greek_small =  ("\N{alpha}" .. "\N{omega}");

Does not work.  If you want non-ascii ranges, try

   my @greek_small =  map { chr } ( ord("\N{alpha}") .. ord("\N 
{omega}") );

On the other hand, ranges in regexp and C<tr///> works.  You may  
consider this inconsistent but range operator must accept variables  
like <tt>($start .. $end)</tt> while character ranges in regexp is  
constant.

=cut

Dan the Range (?:Ar)ranger
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.