perl-unicode

Re: Looping with Unicode

2003-03-07 00:30:04
On Thu, Mar 06, 2003 at 05:30:37PM -0500, Daniel Yacob wrote:
Greetings,

I seem to remember in the past, possibly with a development
version of Perl, that unicode chars in utf-8 worked fine as
loop iterators, as per:

foreach (<a>..<z>) {  do something }

where <a> and <z> are single characters in utf-8.  With Perl
5.8.0 the loop cycles only once.  Is this a bug or by design?

I doubt that this could have ever worked.  The ".." has always been
defined to work for string scalars only over the "ASCIIbetic" ranges
"a".."z" and "A".."Z".  Making that work for Unicode scalars would
require extra code of which I see no trace.  Not to mention that the
logical semantics for this would be rather ... odd. What should
"a"..chr(0x100) generate, for example?

Can something be set in the script to make it work as expected?

An observation;  UTF-8 keys in a hash can be defined without
quotation:

%myHash =(
      <abc> => "this",
      <xyz> => "that",
        :   :     :
);

but later the keys must be referenced in quoted form.  That

Hmmm, that *should* work under 'use utf8'.

is $myHash{'<abc>'} returns a value, $myHash{<abc>} does not.
This seems a little inconsistent and misleading.  I favor the
quoteless style myself.  Again, did I forget to set something?
(yes I did try "use utf8;").

thanks!

/Daniel

-- 
Jarkko Hietaniemi <jhi(_at_)iki(_dot_)fi> http://www.iki.fi/jhi/ "There is this 
special
biologist word we use for 'stable'.  It is 'dead'." -- Jack Cohen

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