[vienna.pm] perl 5.6.0 und UTF8

Peter J . Holzer hjp at wsr.ac.at
Tue Aug 29 11:39:57 CDT 2000


Hat sich damit schon wer gespielt? Wenn ich perldoc utf8 richtig
verstehe, dann sollte sich perl für jeden String merken ob er aus UTF8
Characters oder Bytes besteht und ihn entsprechend behandeln. 

Irgendwie scheint es das auch zu tun, aber ich kann kein sinnvolles
System entdecken, nachdem es entscheidet, wann ein String UTF8 ist und
wann nicht. Manchmal werden Strings in UTF8 umgewandelt obwohl sie es eh
schon sind, manchmal werden sie nicht umgewandelt, obwohl es notwendig
wäre ...

Hier ist ein kleines Script als Demo:


#!/usr/local/bin/perl -w
use strict;
use utf8;

#my $ats = chr(0366) . "S";
my $ats = pack("U", 0366) . "S";
my $euro = chr(8364);
my $ue = pack("U", 0374);

my $a;

$a = "Ein $ue kostet 43 " . $ats . "\n";
print $a;

$a = "Ein $ue kostet 43 " . $euro . "\n";
print $a;

$a = "Ein " . $ue . " kostet 43 " . $euro . "\n";
print $a;

$a =  "43 " . $euro . " kostet ein " . $ue . "\n";
print $a;

$a = substr($a, 0, 10) . "\n";
print $a;

$a = chr(0xFEFF) . "Ein \x{00FC} kostet 43 " . $ats . "\n";
print $a;

	hp

-- 
   _  | Peter J. Holzer      | Any setuid root program that does an
|_|_) | Sysadmin WSR / LUGA  | exec() somewhere is just a less
| |   | hjp at wsr.ac.at        | user friendly version of su.
__/   | http://www.hjp.at/   |    -- Olaf Kirch on bugtraq 2000-08-07
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 371 bytes
Desc: not available
Url : http://mail.pm.org/archives/vienna-pm/attachments/20000829/3bad4ae2/attachment.bin


More information about the Vienna-pm mailing list