Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error in printing unicode

1 view
Skip to first unread message

Vlad Stanimir

unread,
May 8, 2008, 1:32:59 PM5/8/08
to Perl mailing list
I just finished reading "Beginning Perl by Simon Cozens Chapter 1: First
Steps In Perl" and i tried to print a Unicode character using the \x{}
but i got a strange outcome i don't understand.
The code was:

#!/user/bin/perl
use warnings;
print "\x{2620}\n";

and the result was:

Wide character in print at C:\Documents and
Settings\Vlad\desktop\test.plx line 3.
?яб

I used windows xp
cmd.exe
and i have activeperl 5.10.0 build 1002

Daniel McClory

unread,
May 8, 2008, 3:21:35 PM5/8/08
to Vlad Stanimir, Perl mailing list
There are basically 3 lines that you'll want to be using if you're
going to be using unicode in your perl scripts - one for input, one
for output, and one for using unicode characters within the perl
script itself.

binmode STDOUT, ":utf8"; #this tells perl that the stdout is to be
encoded as utf8
open (INPUT, "<:utf8", $ARGV[0]); #this tells perl that the input
file is encoded as utf8
use utf8; #this tells perl that there are unicode characters
inside the .pl file

so for what you're talking about, you only need to include that line
at the beginning of a program, but you might find it helpful to have
the other 2, for future reference.

Dan

On May 8, 2008, at 1:32 PM, Vlad Stanimir wrote:

> I just finished reading "Beginning Perl by Simon Cozens Chapter 1:
> First Steps In Perl" and i tried to print a Unicode character using
> the \x{} but i got a strange outcome i don't understand.
> The code was:
>
> #!/user/bin/perl
> use warnings;
> print "\x{2620}\n";
>
> and the result was:
>
> Wide character in print at C:\Documents and Settings\Vlad\desktop
> \test.plx line 3.

> ?ÿá


>
> I used windows xp
> cmd.exe
> and i have activeperl 5.10.0 build 1002
>
>

> --
> To unsubscribe, e-mail: beginners-...@perl.org
> For additional commands, e-mail: beginne...@perl.org
> http://learn.perl.org/
>
>

Dr.Ruud

unread,
May 8, 2008, 4:48:03 PM5/8/08
to begi...@perl.org
Daniel McClory schreef:

> use utf8; #this tells perl that there are unicode characters
> inside the .pl file


No. From the doc: "Do not use this pragma for anything else than telling
Perl that your script is written in UTF-8."
Also look for "lexical scope" in that doc.

Remember, ASCII characters don't change in UTF-8 encoding. A "use utf8"
in a script written completely in ASCII, would still add access to the
utility functions upgrade() and downgrade().

--
Affijn, Ruud

"Gewoon is een tijger."

0 new messages