it works for this particular file but not for my complex script

I do not understand. What is a complex script? What does not work? Explain this, use more words.

How can I force CGI to use utf8 as default?

Exactly as I have shown. There are several parts to it:

1. use utf8; lets you write literal UTF-8 characters in Perl source code. If you always use Perl escapes instead, such as \x{11b} and HTML escapes, such as ě, so that you have ASCII-only source-code, this pragma is not neccesary.

2. The header method sets the HTTP header with the appropriate encoding. You seem to be under the misconception that <meta name="charset" content="utf-8"/> is enough. In fact the HTTP header is always relevant, and the in-file meta header only is taken into consideration when the HTTP header is absent, e.g. when the HTML is loaded from the file system.

3. CGI writes to STDOUT. The binmode method inherited from IO::Handle sets the encoding to UTF-8 for any STDOUT output, e.g. print method.

And how is it possible that all other national chars (ščřžýáíéůú) are good

I do not understand this question. All characters have the same properties, or nearly so, so of course they behave the same as with ě from the original example. Perhaps you should start to show some source code to demonstrate what you mean.


In reply to Re^3: CGI.pm encoding - wrong encoding for &#283; by Anonymous Monk
in thread CGI.pm encoding - wrong encoding for &#283; by koszta5

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.