Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Perl on Windows: file names with accented characters, UTF-8 and -e by andal
in thread Perl on Windows: file names with accented characters, UTF-8 and -e by bart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-29 06:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found