Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: encoding of file names

by ikegami (Patriarch)
on Mar 25, 2010 at 20:17 UTC ( [id://830957]=note: print w/replies, xml ) Need Help??


in reply to encoding of file names

Perl treats file names as opaque strings of bytes*. In unix, they are usually characters encoded using the current locale, which in turn, is usually UTF-8.

You need to decode the file names, and you'll be all set.

* — This presents a problem on Windows which stores them as characters, but that's not relevant here.

Replies are listed 'Best First'.
Re^2: encoding of file names
by amir_e_a (Hermit) on Mar 25, 2010 at 20:53 UTC

    Can you please tell me how to decode them? I am not quite experienced with Encode. I still don't understand what to specify as the from encoding.

    And since you mention it, i actually am curious about Windows, because i plan to make this program portable and i already had similar problems on Windows in the past.

      I still don't understand what to specify as the from encoding.

      Usually, the file names are text encoded as per the local's encoding. In fact, I dare say that's the expectation.

      Most users have a UTF-8 locale. You could assume UTF-8, and worry about it when someone complains.

      If you want to actually get the right encoding, your best bet is probably the following undocumented function:

      require encoding; # Or "use encoding ();" with the parens. my $locale_encoding = encoding::_get_locale_encoding();

      This is what core module open uses.

      And since you mention it, i actually am curious about Windows

      It's a real mess. Bad support by builtins and by modules for accessing Windows's wide character interface. Bad support at finding the code page (last time I checked) of the single-byte interface (even though it's easier than locales in unix). Maybe some other time.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (9)
As of 2024-03-28 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found