Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: replacing close-single-quote with apostrophe

by BillKSmith (Monsignor)
on Nov 08, 2021 at 15:34 UTC ( #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' );


1..1 ok 1 - quote mark test

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2022-01-26 10:25 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.