pbijnens has asked for the wisdom of the Perl Monks concerning the following question:
use utf8; # the literal strings are in utf8
binmode(STDOUT, ":utf8");
my $maxbytes = 5;
my $a= "יטא"; # length: 3 chars, 6 bytes
print $a, "\n";
{
use bytes;
$a = substr($a,0,5) if length($a) > 5;
}
use Encode;
$a = decode_utf8($a,Encode::FB_QUIET);
print $a, "\n"; # 2 chars, 4 bytes now
But I feel there should be something simpler...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: limiting length of utf8 string in bytes
by RMGir (Prior) on Dec 14, 2009 at 12:44 UTC | |
|
Re: limiting length of utf8 string in bytes
by ikegami (Patriarch) on Dec 14, 2009 at 16:59 UTC | |
|
Re: limiting length of utf8 string in bytes
by ambrus (Abbot) on Dec 15, 2009 at 10:57 UTC | |
by ikegami (Patriarch) on Dec 15, 2009 at 14:36 UTC |