CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [7stud] hex metacharacters for characters below x100: Edit Log



7stud
Enthusiast

Mar 29, 2010, 12:56 AM


Views: 5663
Re: [7stud] hex metacharacters for characters below x100

You can also try another test. See what happens if you 'round trip' the string. The following function is from perluniintro. It prints out the string, converting UTF-8 characters to unicode escape sequences:


Code
sub nice_string { 
join("",
map { $_ > 255 ? # if wide character...
sprintf("\\x{%04X}", $_) : # \x{...}
chr($_) =~ /[[:cntrl:]]/ ? # else if control character ...
sprintf("\\x%02X", $_) : # \x..
quotemeta(chr($_)) # else quoted or as themselves
} unpack("W*", $_[0])); # unpack Unicode characters
}


print nice_string("foo\x{0100}bar\n"), "\n";



(This post was edited by 7stud on Mar 29, 2010, 12:57 AM)


Edit Log:
Post edited by 7stud (Enthusiast) on Mar 29, 2010, 12:57 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives