mrd has asked for the wisdom of the Perl Monks concerning the following question:
I'm having troubble with "length" of utf-8 strings. As far as I see, "length" returns correctly the length, in bytes, of a hard-coded string but not of a string read from a file (or STDIN).
The following script correctly prints : 2
but not if $x is read from STDIN:use utf8; $x="\x{0103}"; use bytes; print length($x);
In this case the output is "1".use utf8; binmode(STDIN,":utf8"); $x=<>; chomp $x; use bytes; print length($x);
My environment: WinXP Home Edition, Active Perl 5.8.0.
Thanks for any ideeas.
mrd
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: length in bytes of utf8 string
by Thelonius (Priest) on Jun 27, 2003 at 10:43 UTC | |
by mrd (Beadle) on Jun 27, 2003 at 11:13 UTC | |
|
Re: length in bytes of utf8 string
by graff (Chancellor) on Jun 27, 2003 at 08:48 UTC | |
by zby (Vicar) on Jun 27, 2003 at 09:03 UTC | |
|
Re: length in bytes of utf8 string
by diotalevi (Canon) on Jun 27, 2003 at 08:40 UTC | |
by mrd (Beadle) on Jun 27, 2003 at 09:19 UTC | |
by diotalevi (Canon) on Jun 27, 2003 at 10:06 UTC | |
by mrd (Beadle) on Jun 27, 2003 at 10:21 UTC | |
by diotalevi (Canon) on Jun 27, 2003 at 10:49 UTC | |
|