Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6044537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:01:23+00:00 2026-05-23T07:01:23+00:00

I am trying to use perl’s YAML::XS module on unicode letters and it doesn’t

  • 0

I am trying to use perl’s YAML::XS module on unicode letters and it doesn’t seem working the way it should.

I write this in the script (which is saved in utf-8)

use utf8;
binmode STDOUT, ":utf8"; 
my $hash = {č => "ř"}; #czech letters with unicode codes U+010D and U+0159

use YAML::XS;
my $s = YAML::XS::Dump($hash);
print $s;

Instead of something sane, -: Å is printed. According to this link, though, it should be working fine.

Yes, when I YAML::XS::Load it back, I got the correct strings again, but I don’t like the fact the dumped string seems to be in some wrong encoding.

Am I doing something wrong? I am always unsure about unicode in perl, to be frank…

clarification: my console supports UTF-8. Also, when I print it to file, opened with utf8 handle with open $file, ">:utf8" instead of STDOUT, it still doesn’t print correct utf-8 letters.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:01:23+00:00Added an answer on May 23, 2026 at 7:01 am

    Yes, you’re doing something wrong. You’ve misunderstood what the link you mentioned means. Dump & Load work with raw UTF-8 bytes; i.e. strings containing UTF-8 but with the UTF-8 flag off.

    When you print those bytes to a filehandle with the :utf8 layer, they get interpreted as Latin-1 and converted to UTF-8, producing double-encoded output (which can be read back successfully as long as you double-decode it). You want to binmode STDOUT, ':raw' instead.

    Another option is to call utf8::decode on the string returned by Dump. This will convert the raw UTF-8 bytes to a character string (with the UTF-8 flag on). You can then print the string to a :utf8 filehandle.

    So, either

    use utf8;
    binmode STDOUT, ":raw"; 
    my $hash = {č => "ř"}; #czech letters with unicode codes U+010D and U+0159
    
    use YAML::XS;
    my $s = YAML::XS::Dump($hash);
    print $s;
    

    Or

    use utf8;
    binmode STDOUT, ":utf8"; 
    my $hash = {č => "ř"}; #czech letters with unicode codes U+010D and U+0159
    
    use YAML::XS;
    my $s = YAML::XS::Dump($hash);
    utf8::decode($s);
    print $s;
    

    Likewise, when reading from a file, you want to read in :raw mode or use utf8::encode on the string before passing it to Load.

    When possible, you should just use DumpFile & LoadFile, letting YAML::XS deal with opening the file correctly. But if you want to use STDIN/STDOUT, you’ll have to deal with Dump & Load.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to use the Perl utility/module "prove" as a test harness
I am trying to use XML::RAI perl module on UTF8 coded text and I
I'm trying to find a way to use Perl to further process a PostgreSQL
I'm trying to use the Net::Twitter::Stream Perl module from CPAN to read the stream
I'm trying to use the module HTML::Grabber to parse html in perl. It works
I've been trying to use the Perl module WebService::Blogger (from CPAN) to connect to
Newbie here, I am trying to use Bioperl module in the perl environment. My
I'm trying to use a Perl module from CPAN ( AuthCookieDBI.pm to be specific)
I'm trying to use the bignum module in Perl and want to set the
I'm trying to use Net::SSH::Perl to connect using public keys with this code: my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.