Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

UTF-8 in filenames

by vitoco (Friar)
on Aug 26, 2009 at 20:38 UTC ( #791450=perlquestion: print w/ replies, xml ) Need Help??
vitoco has asked for the wisdom of the Perl Monks concerning the following question:

I need to write a file with some data I get from some UTF-8 encoded pages. No problem in that, except that the name of the file must also be taken from the same page, and garbage is displayed in the filename when listing the directory and a non ASCII char is used.

I found an old thread describing a similar problem, but no solutions other than "don't do that!".

I must use that string (or an ASCII equivalent) as the name of the file. Hints?

Comment on UTF-8 in filenames
Re: UTF-8 in filenames
by moritz (Cardinal) on Aug 26, 2009 at 20:44 UTC

    On windows, file names on NFTS volumes are internally stored in UTF-16, and there are APIs which let you use that (but core perl does not).

    On Unixish systems, any string that doesn't contain a null byte or a slash can be used as file names. They can be in UTF-8, but which character encoding they are stored in is only a convention - the file systems don't store such meta data.

    If you view directory contents with ls, you have to make sure that the current locale and the encoding which your terminal accept are the same as your file names are encoded in.

    If you want to store your filenames in ASCII instead, you can use Text::Unidecode to get a decent ASCII representation of the file name.

    Perl 6 projects - links to (nearly) everything that is Perl 6.
      If you want to store your filenames in ASCII instead, you can use Text::Unidecode to get a decent ASCII representation of the file name.

      Great! That was the hint I needed. Thanks a lot...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://791450]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2014-09-22 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (178 votes), past polls