This was posted to comp.lang.perl.misc with no replies. Hello, I'm trying to understand the correct way to handle the following. Say I have a file containing non ascii characters, e.g. as 8 bit values 66 69 6C E9, or 'f' 'i' 'l' 'e_acute', and I want to establish whether that file exists. If I execute:
ex("c:\\fil\x{e9}.txt"); ex("c:\\fil" . pack("U", 0xe9 ) . ".txt"); sub ex { my $f = shift; print $f; print ((-e $f) ? " exists" : " doesn't exist"); print "\n"; }
Then I get the following:
c:\filé.txt exists c:\filé.txt doesn't exist
The filename is displayed in exactly the same format to the screen in both cases, but the file isn't found when the filename is passed as a utf8 string. Is there any way to tell perl that the operand being passed to -e is utf8? One workaround would be to simply convert everything from utf8 to an single byte representation, but I've no idea whether this will work in environments other than mine (Win32, EN_GB, perl v5.8.8). It's also not going to handle unicode characters that won't fit into a single byte either. What is the correct way to handle this to ensure portability? Chris Key

In reply to utf8 filenames by cjk32

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.