Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi all,

after reading Encoding horridness i played around a bit:

#!/usr/bin/env perl # $Id: weird.pl,v 1.3 2017/07/13 09:06:54 karl Exp karl $ use strict; use warnings; use feature qw(say); 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)'; say <$fh>; close $fh; __END__

This is leading to:

karls-mac-mini:monks karl$ ./weird.pl weird.txt: text/plain; charset=utf-8 de_DE.UTF-8 nase göre nase göre

And if i say use utf8; i get:

karls-mac-mini:monks karl$ ./weird.pl weird.txt: text/plain; charset=utf-8 de_DE.UTF-8 nase göre nase g?re

What do i miss?

Thanks for any hint and best regards, Karl

Update: Two working solutions:

Update2: Sorry, wrong merits.

1nickt:

#!/usr/bin/env perl # $Id: weird_1nickt.pl,v 1.2 2017/07/13 17:10:29 karl Exp karl $ + use strict; use warnings; use feature qw(say); use utf8; 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)'; say <$fh>; close $fh; __END__ karls-mac-mini:monks karl$ ./weird_1nickt.pl weird.txt: text/plain; charset=utf-8 de_DE.UTF-8 nase göre nase göre

choroba:

#!/usr/bin/env perl # $Id: weird_choroba.pl,v 1.2 2017/07/13 20:47:38 karl Exp karl +$ use strict; use warnings; use feature qw(say); use utf8; use open IO => ':encoding(utf-8)', ':std'; my $file = q(weird.txt); open( my $fh, '>', $file ); say $fh qq(nase\ngöre); close $fh; say qx (file -I $file); say qx(echo \$LANG); say qx(cat $file); open( $fh, '<', $file ); say <$fh>; close $fh; __END__ karls-mac-mini:monks karl$ ./weird_choroba.pl weird.txt: text/plain; charset=utf-8 de_DE.UTF-8 nase göre nase göre

«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


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (6)
As of 2024-03-28 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found