Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: replacing close-single-quote with apostrophe

by BillKSmith (Monsignor)
on Nov 08, 2021 at 15:34 UTC ( [id://11138576]=note: print w/replies, xml ) Need Help??


in reply to replacing close-single-quote with apostrophe

As others have already shown, it is best to separate the functions of decode and translation. The following code demonstrates a few minor improvements. The use of character names allows you to type your script in pure ascii. It makes your intention clear without concern about how very similar looking graphics are displayed (Probably the same reasons that you used informal character names in your post). I prefer the use of the tr/// operator rather than s///g for fixed substitutions such as this.
use strict; use warnings; use Encode 'decode'; use Test::More tests=>1; my $in_file = qq(This isn\xe2\x80\x99t hard); my $text = decode('utf-8', $in_file); $text =~ tr/\N{RIGHT SINGLE QUOTATION MARK}/\N{APOSTROPHE}/; is( $text, q(This isn't hard), 'quote mark test' );

OUTPUT:

1..1 ok 1 - quote mark test
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-26 08:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found