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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.