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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hardly an elegant solution, but my little script will do exactly what you want.

#!/usr/bin/perl -n #use strict; #use warnings; use charnames (); use encoding "utf8"; $|++; my $chars = { 'HYPHEN' => '-', # \x{2010} 'SOFT HYPHEN' => '-', #­ \x{00AD} 'MINUS SIGN' => '-', # \x{2212} 'FIGURE DASH' => '-', # \x{2012} 'ACUTE ACCENT' => "'", # \x{00B4} 'GRAVE ACCENT' => "'", # \x{0060} 'LEFT SINGLE QUOTATION MARK' => "'", # \x{2018} 'RIGHT SINGLE QUOTATION MARK' => "'", # \x{2019} 'LEFT DOUBLE QUOTATION MARK' => '"', # \x{201C} 'RIGHT DOUBLE QUOTATION MARK' => '"', # \x{201D} 'BOX DRAWINGS LIGHT VERTICAL' => '|', # \x{2502} 'MULTIPLICATION SIGN' => '*', # \x{00D7} 'BACKSPACE' => '', # \x{0008} 'DELETE' => '', # \x{0127} }; # If the first character is an equal sign, skip it and # display the identity of each remaining character. # if (/^=/) { chomp; for my $index ( 1 .. length($_) - 1 ) { my $char = substr( $_, $index++, 1 ); print $char . " " . ord( $char ) . " " . sprintf( "\\%03o", ord($char) ) . " " . sprintf( "\\x{%04X}", ord($char) ) . " = '" . charnames::viacode( ord($char) ) . "'\n" ; } } else { for my $cname ( keys %$chars ) { my $char = chr( charnames::vianame($cname) ); s/$char/$chars->{$cname}/g; } print; }

Run this and it sits there waiting for you to paste something to your terminal. Once it receives some input, it starts replacing characters by their unicode name with the values from the $chars hashref.

If you need to identify any unicode characters because you want to add to the hashref of replacement characters, press the = key first and then paste to your terminal.

--
Andy


In reply to Re: Replacing non ascii in string by naChoZ
in thread Replacing non ascii in string by IanD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found