Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Problems w/ encoding in terminal

by choroba (Bishop)
on Aug 06, 2013 at 11:43 UTC ( #1048098=note: print w/replies, xml ) Need Help??

in reply to Problems w/ encoding in terminal

What encoding do you use to save the script? If you save it as utf-8 and tell Perl you did so by
use utf8;
everything should just work (i.e. no Encode, output set to utf-8, terminal set to utf-8).
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Problems w/ encoding in terminal
by humble (Acolyte) on Aug 29, 2013 at 11:59 UTC
    What would you advice me to correctly output a file content from the same my script? - Again, the file content is in UTF8, but in UTF8 terminal it is not readable since outputed from my script. Do i have to decode the file content every time i want to output it using 'Encode' module?
      Just tell Perl what encoding the file uses. There are several ways:

      When opening the file

      open my $OUT, '>:utf8', $filename or die $!;

      Or, after opening the file:

      open my $OUT, '>', $filename or die $!; binmode $OUT, ':utf8';

      Or, if you want all your output be in UTF-8:

      use open OUT => ':utf8';

      See open, open, binmode for details. You can also use ':encoding(UTF-8)' instead of ':utf8' to let Perl check the validity of the data.

      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        Awesome! Thank you exceedingly much!

        Thank you very much! It worked.

        Now i have investigated a bit farther on the web and found there is a module

        use utf8::all;

        seems very interesting to me.

        But i got a problem since i have included it:

        utf8 "\xB4" does not map to Unicode (pointing to line 8, please read farther)

        on running my script1, where i set:

        use utf8::all; require 'script2';

        In the script2 i have:

        1 # again 2 use utf8::all; 3 4 sub openfile{ 5 my $file=shift @_; 6 my $cont; 7 open my $fh, '<', $file || die "sopen: Cann't open $file $!"; 8 do{ 9 $cont.=<$fh>; 10 }until( eof( $fh ) ); 11 close $fh; 12 return $cont; 13}

        So, why is it so?

Re^2: Problems w/ encoding in terminal
by humble (Acolyte) on Aug 24, 2013 at 09:34 UTC
    Thank you very much: worked and so i will be watching for the directive to use in the future!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048098]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-03-25 03:48 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (300 votes). Check out past polls.