Use oct instead of eval.
Use Encode's encode to find the UTF-8 encoding.
use Encode qw( encode ); my $unicode_codepoint_hex_lit = '0x20ac'; my $unicode_codepoint_integer = oct( $unicode_codepoint_hex_lit ); my $unicode_char = chr( $unicode_codepoint_integer ); my $utf8_bytes = encode( 'UTF-8', $unicode_char ); my @utf8_bytes = map ord, $utf8_bytes =~ /./sg; my @nohi_bytes = map $_ & 0x7F, @utf8_bytes; print(join(' ', map sprintf('%02X', $_), @utf8_bytes), "\n"); print(join(' ', map sprintf('0x%02X', $_), @utf8_bytes), "\n"); print(join(' ', map unpack('B8', pack('C', $_)), @utf8_bytes), "\n"); print("\n"); print(join(' ', map sprintf('%02X', $_), @nohi_bytes), "\n"); print(join(' ', map sprintf('0x%02X', $_), @nohi_bytes), "\n"); print(join(' ', map unpack('B8', pack('C', $_)), @nohi_bytes), "\n");
E2 82 AC 0xE2 0x82 0xAC 11100010 10000010 10101100 62 02 2C 0x62 0x02 0x2C 01100010 00000010 00101100
In reply to Re: Need Help With Seemingly Bizarre Unicode Task
by ikegami
in thread Need Help With Seemingly Bizarre Unicode Task
by Jim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |