From: "Brian Schröder" Date: 2005-04-28T22:49:50+09:00 Subject: Re: $KCODE reference documentation On 28/04/05, Mark Hubbart wrote:> On 4/27/05, Bertram Scharpf wrote:> > Am Sonntag, 24. Apr 2005, 21:04:31 +0900 schrieb dm1:> > > Hello, i know that one can use $KCODE to set the charset encoding, but do> > > not find anymore where this is documented. Any pointers for that ?> >> > As far as I see when the source code is read the `-K' option> > and the inline pragma (`# -*- ...') apply. After that,> > `$KCODE' only influences what Regexp's dot (`/./') does.> >> > But that's just a guess.> > It also affects legal names:> > --> #!/usr/bin/env ruby -Ku> > �� = Math::PI> ��� = -(Time.now - Time.now)> ��� = "300mg Xanax"> def ���(n) Math.sqrt(n) end> def ���(n) n**(1/3.0) end> > puts "�� = #{��}" # Pi> puts "��� = #{���}" # Delta> puts "��� = #{���}" # Perscription symbol> puts "��� 144 = #{��� 144}" # Square root symbol> puts "��� 27 = #{��� 27}" # Cube root symbol> --> > The preceding script only runs properly with the kcode set to utf-8,> due to the unusual variable and method names (some of which may be> unreadable on some systems).> > It seems there might be other effects, to; but basically setting the> kcode should make ruby "really like" the character encoding.> > cheers,> Mark> Thoug there are some annoyances. Especially string lengths are bytelength and some other things: ---8<------8<---#!/usr/bin/ruby -Ku# -*- coding: utf-8 -*- print '| 'puts((('0'..'9').to_a * 5).join)puts "| %10s%10s" % %w(Meier Klaus)puts "| %10s%10s" % %w(Schr��der Brian)puts "| %i != %i" % ['Schr��der'.length, 'Schr��der'.split('').length]---8<------8<--- ./utf8.rb| 01234567890123456789012345678901234567890123456789| Meier Klaus| Schr��der Brian| 9 != 8 which is not aligned. -- http://ruby.brian-schroeder.de/ multilingual _non rails_ ruby based vocabulary trainer:http://www.vocabulaire.org/ | http://www.gloser.org/ | http://www.vokabeln.net/