Re: Weird character issue
- From: "Peter J. Holzer" <hjp-usenet2@xxxxxx>
- Date: Fri, 30 Mar 2007 20:38:14 +0200
On 2007-03-30 17:14, Hoi-Polloi <terry_tn@xxxxxxxxx> wrote:
I'm using Perl 5.6, and I am seeing a very strange behavior with
creating files with utf8 chars in the name. Here's a little program:
use utf8;
use charnames ':full';
my $A = "\x{C1}"; # latin capital letter a with acute
my $AAA = "_" . "$A" . "$A" . "$A";
my $AAA1 = "$A" . "$A" . "$A";
system("echo 'AAA' > $AAA");
system("echo 'AAA1' > $AAA1");
If I run it, then do 'ls' I get the following:
# ls
_ÁÁÁ Ã?ÁÁ
# ls | od -a
qa-tterry-1# ls | od -a
0000000 _ ? 81 ? 81 ? 81 nl ? 83 ? 81 ? 81 ?
81
0000020 nl
0000021
In other words, the first character of the AAA1 file is not latin
capital a acute. I am surprised that putting "_" at the beginning of
the string makes a difference. What is going on here?
Firstly, please upgrade to a current version of perl. Perl 5.6.0 was the
first version with some UTF-8 support, and it has many issues which have
since been fixed. People will probably ignore your UTF-8 problems if you
don't have at least perl 5.8.1.
Secondly, you are using system to invoke a shell command. The problem
could be a shell problem just as easily as it could be a perl problem.
If you want to demonstrate that it is a perl problem you should use
open to create the file. (and in any case you should explicitely encode
the filename).
hp
--
_ | Peter J. Holzer | Blaming Perl for the inability of programmers
|_|_) | Sysadmin WSR | to write clearly is like blaming English for
| | | hjp@xxxxxx | the circumlocutions of bureaucrats.
__/ | http://www.hjp.at/ | -- Charlton Wilbur in clpm
.
- References:
- Weird character issue
- From: Hoi-Polloi
- Weird character issue
- Prev by Date: Isolate lines in a text file and perform replacements
- Next by Date: regular expression help
- Previous by thread: Weird character issue
- Next by thread: Isolate lines in a text file and perform replacements
- Index(es):
Relevant Pages
|
|