Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

wide character warning!

by DragonCoder (Initiate)
on Nov 06, 2014 at 09:03 UTC ( [id://1106339]=perlquestion: print w/replies, xml ) Need Help??

DragonCoder has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks! I am a newbie in perl and have lots of problems in coding .. i am facing an error that says something like this.. Wide character in say at ./characters_codepoint.pl line 13. אαω and can u suggest me the best ways to learn perl, i am currently reading learning perl and practicing in a terminal on my mac.

#!/usr/bin/perl -w use 5.018; open(OUT,">out.html"); binmode(OUT, "utf8"); use utf8; my $alef = chr(0x05D0); my $alpha = chr(hex('03B1')); my $omega = chr(0x03C9); say "$alef$alpha$omega";

Replies are listed 'Best First'.
Re: wide character warning!
by Loops (Curate) on Nov 06, 2014 at 09:25 UTC

    Hi, and welcome to the monastery.

    If you add "use diagnostics;" in addition to your "use 5.018;" Perl will give you a helpful error with a solution:

    binmode STDOUT, ':utf8';

    Although another choice if you want to configure all of Perl's Unicode options is the utf8::all module.

      Just a Note:
      ":utf8" only marks the data as UTF-8 without checking whether the data is a valid UTF-8, meanwhile ":encoding(UTF-8)" checks that the data are actually valid UTF-8.
      So, I will rather write:

      binmode(STDOUT, ":encoding(utf8)");

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me
Re: wide character warning!
by Anonymous Monk on Nov 06, 2014 at 09:17 UTC

    STDOUT is not OUT, you forgot to say to out; also error checking like autodie , Path::Tiny is convenience

    use Path::Tiny qw/ path /; my $outfh = path( "out.html" )->openw_utf8; say $outfh "\x{FEFF}\x{1F42A}\x{1F42B}"; close $outfh;

    shorter :)

    use Path::Tiny qw/ path /; path( "out.html" )->spew_utf8( "\x{FEFF}\x{1F42A}\x{1F42B}" );
Re: wide character warning!
by Anonymous Monk on Nov 06, 2014 at 11:37 UTC
    say "$alef$alpha$omega";
    This is the same as
    say STDOUT "$alef$alpha$omega"
    I recommend you to use the following prelude in your programs:
    use 5.018; use diagnostics; use utf8; # this tells perl that the source code is in utf-8 use open qw( :encoding(utf-8) :std ); # perl will try to open everythi +ng in utf-8 mode by default
    Or you can use the utf8:all module.
    can u suggest me the best ways to learn perl, i am currently reading learning perl
    The Perl code you provided is pretty bad, to be frank. If that is what 'Learning Perl' teaches then I'd recommend you to stop reading it. Try 'Modern Perl' instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1106339]
Approved by Eily
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-20 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found