Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Perl on Windows: file names with accented characters, UTF-8 and -e

by andal (Hermit)
on May 12, 2016 at 07:31 UTC ( [id://1162842]=note: print w/replies, xml ) Need Help??


in reply to Perl on Windows: file names with accented characters, UTF-8 and -e

Your understanding is correct. Everything depends on which Encoding is used to store file names in your Windows (well on Linux also, but normally Linux uses only UTF-8, but there are some exotic cases). You can try to use some standard modules mentioned by others. Or you can try to play with encodings of strings. There's very powerful and simple module Encode that comes with perl. Use that module to convert your strings to desired encoding.

There's one tricky point though. Perl can be configured to automatically apply conversion to data received from OS. That automatic conversion may be wrong and/or may confuse. In general, OS passes to perl "octets", perl may convert them to "characters" (automatically or per request). Normally when working with file names also perl has to pass to OS "octets".

So, if you know that you get data from file in UTF-8 encoding and Windows encodes file names using CP1252, then you'd have to do the following

Encode::from_to($fname, "UTF-8", "CP1252");
But the above code assumes that $fname contains "octets" (Encode::is_utf8($fname) returns false). If it already contains "characters", then the code shall be
$fname = Encode::encode("CP1252", $fname);

Read through perldoc Encode to get the details.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1162842]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-16 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found