Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How to sanely handle unicode in perl?

by Khen1950fx (Canon)
on Mar 21, 2015 at 11:45 UTC ( #1120833=note: print w/replies, xml ) Need Help??


in reply to How to sanely handle unicode in perl?

Here's a simpler version of choroba's idea:
#!/usr/bin/perl -l use strict; use warnings; open my $in, "-|:encoding(UTF-8)", "echo \xc3\xb6" or die $!; my $line = <$in>; chomp($line); open STDOUT, ">-" or die $!; binmode STDOUT, ":encoding(UTF-8)"; print STDOUT "I read a line, that is ", length($line), " chars long.\n +"; print STDOUT "That line in ascii is: $line"; close($in); close(STDOUT); exit 0;
Updated: Fixed mistake at line 11. Thanks, choroba!

Replies are listed 'Best First'.
Re^2: How to sanely handle unicode in perl?
by choroba (Bishop) on Mar 21, 2015 at 18:12 UTC
    Line 11 makes no sense. When you add the failure handling, you'll know why:
    open STDOUT, ":encoding(UTF-8)" or die $!;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Thanks for noticing. Of course, it makes no sense. My editor went a wee bit wonky on me. My bad---That's what I get for not looking at it again afterwards:).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1120833]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2019-05-23 20:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (146 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!