$KCODE reference documentation

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 ?

Thanks

Denis

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.

Bertram

···

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 ?

--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

It also affects legal names:

···

On 4/27/05, Bertram Scharpf <lists@bertram-scharpf.de> 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.

--
#!/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

> > 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 byte
length 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.

···

On 28/04/05, Mark Hubbart <discordantus@gmail.com> wrote:

On 4/27/05, Bertram Scharpf <lists@bertram-scharpf.de> wrote:
> Am Sonntag, 24. Apr 2005, 21:04:31 +0900 schrieb dm1:

--
http://ruby.brian-schroeder.de/

multilingual _non rails_ ruby based vocabulary trainer:
http://www.vocabulaire.org/ | http://www.gloser.org/ | http://www.vokabeln.net/