On Sat, Apr 1, 2017 at 4:24 AM, K. Peng <[email protected]> wrote:
> I don't know why the "ref" and "scalar" functions here can be used to
> validate if it's ASCII or UTF8 encoding.
>
>
> use constant ASCII => ref eval {
> require Encode;
> Encode::find_encoding('ascii');
> };
>
> use constant UTF8 => scalar eval {
> Encode::encode_utf8( chr(182) ) eq pack( 'H*', 'C2B6' );
> };
>
Not entirely clear but the constant ASCII will have a value of "Encode::XS"
if 'ascii' is found as a valid encoding and UTF8 will have the value "1" if
the utf8 encoding of "chr 182" matches the "Hex string (high nibble first)
of "C2B6" - appears to be the paragraph char.
use constant ASCII => ref eval {
require Encode;
Encode::find_encoding('ascii');
};
print "r: ", eval { Encode::find_encoding('ascii');
}, "\n";
print "r: ", ref eval { Encode::find_encoding('ascii');
}, "\n";
print "r: ", ref Encode::find_encoding('ascii') , "\n";
print "r: ", ref Encode::find_encoding('himom') , "\n";
use constant UTF8 => scalar eval {
Encode::encode_utf8( chr(182) ) eq pack( 'H*', 'C2B6' );
};
print "s: ", eval { Encode::encode_utf8( chr(182) ) eq pack( 'H*',
'C2B6' );
}, "\n";
print "s: ", scalar eval { Encode::encode_utf8( chr(182) ) eq pack(
'H*', 'C2B6' );
}, "\n";
print "s: ", Encode::encode_utf8( chr(182) ) eq pack( 'H*', 'C2B6'
) , "\n";
printf("c: %c %s\n", chr(182), pack( 'H*', 'C2B6' ) );
$ perl /tmp/r.pl
r: Encode::XS=SCALAR(0xb39ff0)
r: Encode::XS
r: Encode::XS
r:
s: 1
s: 1
s: 1
c: ΒΆ
--
a
Andy Bach,
[email protected]
608 658-1890 cell
608 261-5738 wk