perl-unicode

Re: range operator vs. unicode

2006-06-08 01:56:54
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

<Prev in Thread] Current Thread [Next in Thread>