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

Re: Encoding horridness revisited: What's going on here?

by 1nickt (Canon)
on Jul 13, 2017 at 13:14 UTC ( [id://1195019]=note: print w/replies, xml ) Need Help??


in reply to Encoding horridness revisited: What's going on here? [SOLVED]

Hi Karl,

What do i miss?

As I understand it, you missed telling Perl to encode your STDOUT output as UTF-8, after you read it in the second time (from the file). You don't need to (should not) do so when printing the output of cat, since your terminal already handles the encoding correctly.

use strict; use warnings; use feature qw(say); use utf8; # <-- needed, since you have high characters in your source my $file = q(weird.txt); open( my $fh, '>', $file ); binmode $fh, ':encoding(UTF-8)'; say $fh qq(nase\ngöre); close $fh; say qx (file -I $file); say qx(echo \$LANG); say qx(cat $file); open( $fh, '<', $file ); binmode $fh, ':encoding(UTF-8)'; binmode STDOUT, ':encoding(UTF-8)'; # <-- here say <$fh>; close $fh; __END__


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Encoding horridness revisited: What's going on here?
by choroba (Cardinal) on Jul 13, 2017 at 14:08 UTC
    Or just add
    use utf8; use open IO => ':encoding(UTF-8)', ':std';

    and remove all binmode or :encoding in open calls.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      This works! I'll try the solution from 1nickt and update the OP. Very nice!

      Thank you very much, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re^2: Encoding horridness revisited: What's going on here?
by karlgoethebier (Abbot) on Jul 13, 2017 at 17:28 UTC

    This works as well! Please see my update above.

    Thank you very much, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-16 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found