perl-unicode

Matching encoded strings and file names

2005-12-20 02:46:52


Hello,

  I have the following problem I need to solve. I hope someone
here can help me with that. Let's say I have a txt file which
contains a list of strings. Some of these strings contain
characters encoded in this fashion:


R\xC3\xA9union (\xC3\xA9 is one character - e with an accent).


  I also have directory which contains many files, some of which
also contain these special characters. What I would like to do
is find any strings from the txt file that match file names in
the directory. I have tried the following. Assuming
'R\xC3\xA9union' is in $in and the current file name from the
directory is in $file:


$in =~ s/\\x(..)/chr(hex($1))/eg;
$file =~ s/\..*//; # get rid of the extension


if ( $in eq $file ) {
    print "Success.\n";
}
else {
    print "Join the perl-unicode mailing list and seek help.\n";
}

Now, this fails, even though when I look at the file name it is
Reunion (with accented e). This fails because my $in =~ s///
didn't produce an accented e, although I've checked that \xC3\xA9
is the correct encoding for that character. Can you please tell
me what I am doing wrong and, more generally, how to correctly
make these kinds of string comparisons with strange characters?

Thank you!


Best regards,
Angie


<Prev in Thread] Current Thread [Next in Thread>