Question

I use quotemeta to escape for file path of Chinese filename. But it returns wrong.

Example of the code:

#!/usr/bin/perl

use Encode;
my $ustring1 = "/opt/游戏美术.txt";
my $ustring2 = quotemeta $ustring1;

print "$ustring1\n" ;
print "$ustring2";
print "\n";

Please help to explain and provide the code to solve this. I'm using Perl v5.10.1 Thanks a lot.

Update question:

#!/usr/bin/perl

use Encode;
use utf8;
use open ':std', ':encoding(UTF-8)';

my $ustring1 = "游戏美术";
my $ustring2 = quotemeta $ustring1;
my $rc = 0xffff & system("echo a > $ustring1.txt2");


print "$ustring1\n" ;
print "$ustring2\n";
print "$rc";
print "\n";

The output is fine now. But the filename of the txt2 file is wrong: 游??美术.txt2. Please help

Was it helpful?

Solution

Maybe, use utf 8 helps:

#!/usr/bin/perl

use Encode;
use utf8;
use open ':std', ':encoding(UTF-8)';

my $ustring1 = "/opt/游戏美术.txt";
my $ustring2 = quotemeta $ustring1;

print "$ustring1\n" ;
print "$ustring2";
print "\n";

Output:

/opt/游戏美术.txt
\/opt\/游戏美术\.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top