开发者

Unable to remove right single quotation mark

Been trying to remove a right single quotation mark from data coming into a Perl form unsuccessfully. If I paste the text: ( Can’t Be Dodged ) into the form it never removes the right single quotation mark. I've tried different methods of encoding and escaping the Unicode and nothing seems to work.

Below is what I'm working wit开发者_如何学JAVAh.

#!/usr/bin/perl
use strict;
use CGI::Carp qw( fatalsToBrowser carpout);
use CGI '-utf8';
my $q = CGI->new;
my $buffer = $q->param( 'q' );
print "Content-Type: text/html; charset=UTF-8", "\n\n";
$buffer =~ s/[\'\`\.]//g;
$buffer =~ s/’//sg;
print "$buffer";


I think you might like Text::Demoronise.


So, the trick is to figure out what the character is. One solution is to do something like this:

for my $c (split //, $buffer) {
    printf "[$c]: %x\n", ord $c;
}

Once you know what the character is, removing it is simple.


I changed the substitution line to:

$buffer =~ s/[\'\’\.]//g;

This is my result from the command line:

$ ./test.pl q="( Can’t Be Dodged )"
Content-Type: text/html; charset=UTF-8

( Cant Be Dodged )
$ 

The same string but using an escaped left single quote produced the same result using the original code.

Edit

I've cleaned up the output - the command prompt is now just '$', and there is a newline added to the end of the output, this makes it easier to see the relevant output.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜