Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Converting utf-8 to Hex

by hippo (Bishop)
on Jun 11, 2017 at 11:42 UTC ( [id://1192521]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Converting ASCII to Hex
in thread Converting ASCII to Hex

Here's one method. Doubtless there's a neater approach but this works for your single example. Feel free to add to @tests to convince yourself that it is doing what you want.

#!/usr/bin/env perl use strict; use warnings; use Encode; use Test::More; my @tests = ( { source => "\x{2013}", want => 'E2 80 93' } ); plan tests => scalar @tests; for my $t (@tests) { Encode::_utf8_off ($t->{source}); # bytes my $have = uc unpack "H*", $t->{source}; # into hex $have = join (' ', $have =~ /(..)/g); # spaced pairs is ($have, $t->{want}, "Covert $t->{source} into $t->{want}"); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1192521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-26 06:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found