This is a bit tricky and a known shortcoming of Perl which isn't all that easy to fix.

To start with, Perl does not know which encoding the file system applies to represent polish characters, and you have no way of specifying it. So, the name of your source file is known to Perl as bytes, encoded in whatever encoding the file system chooses. Nowadays, unless you are on Windows, UTF-8 is a reasonable guess, but Perl does not guess.

Your command line parameter -CS then enforces UTF-8 encoding of STDERR, which is fine for the characters in your error message but not for file names. So, you get the file name doubly encoded.

One way to get out of this is to apply encoding yourself, and drop the command line parameters. This sort of works, but makes the assumption that the file name is encoded in UTF-8:

#!/usr/bin/perl
# saved as ąćęłńó.pl

use utf8;

use Encode qw(encode);

die encode('UTF-8',"language specific chars: ąćęłńó");

Edited because I forgot (again) that the code tags break non-ASCII characters


In reply to Re: Special character in file name -- die error messed up by haj
in thread Special character in file name -- die error messed up by leszekdubiel

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.