in reply to Bytes in a String
A more generic technique for determining the length of a string in a given output encoding:use strict; use warnings; my $x = "abcdefg"; print length $x, "\n"; { use bytes; print length $x, "\n"; } open my $fh, ">:encoding(ucs-2)", "out.txt" or die $!; print $fh $x; close $fh; print +(stat "out.txt")[7], "\n"; #print size of file in bytes __END__ 7 7 14
use Encode qw/encode/; my $x = "abcdefg"; print length(encode("ucs-2", $x)), "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Bytes in a String
by ysth (Canon) on Jul 03, 2005 at 08:40 UTC |