Re: Weird character issue



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
.



Relevant Pages

  • Weird character issue
    ... I'm using Perl 5.6, and I am seeing a very strange behavior with ... creating files with utf8 chars in the name. ... the string makes a difference. ...
    (comp.lang.perl.misc)
  • Re: Shell-escaping from perl
    ... > Suppose I want to invoke a shell command from perl and provide some ... I already know how to write a regular expression to do this - ... > standard perl module somewhere that will do this. ...
    (comp.lang.perl.misc)
  • RE: Perl code security (CGI related)
    ... > command in perl code ... ... Perl code security ... > However it does not have any effect if $code is shell command such as ... > The cgi program is running on apache 2.0 running under user apache. ...
    (SecProg)
  • Re: obfuscated
    ... js> I have to test it does not walk but in 2000 it is odd Perl of the times ... why are you using LWP to read a LOCAL file? ... would you slurp something which has already been read in by LWP? ... that is a shell command but what are the doing? ...
    (comp.lang.perl.misc)
  • Re: Date manipulation
    ... Perl knows what time it is. ... It's silly to run a shell command to get ... sub get_time { ... print FILE ...
    (perl.beginners)