akho has asked for the wisdom of the Perl Monks concerning the following question:
I have a severe misunderstanding; how do encodings work in Perl?
I have a script that takes text as input and basically does several substitutions to it. The text itself contains cyrillic characters; some substitutions have non-ascii characters.
Actually, this script reproduces the problem:
use utf8; while (<>) { s/<</«/g; print; }
If I try to use it on the console or redirect its output to a file, it keeps cyrillic characters but messes up the « (replaces it with �). But if I run it on a block in Vim, it does the right substitution but destroys cyrillic characters (replacing each of them with two unreadable bytes, obviously).
What should I do? Can someone point me to a comprehensive guide to encodings?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: I/O encoding question
by ysth (Canon) on May 06, 2007 at 18:47 UTC | |
|
Re: I/O encoding question
by shmem (Chancellor) on May 06, 2007 at 18:59 UTC | |
|
Re: I/O encoding question
by Krambambuli (Curate) on May 06, 2007 at 19:15 UTC | |
by akho (Hermit) on May 06, 2007 at 21:00 UTC | |
by Joost (Canon) on May 06, 2007 at 21:31 UTC | |
by almut (Canon) on May 06, 2007 at 22:35 UTC |