Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Problems w/ encoding in terminal

by choroba (Abbot)
on Aug 29, 2013 at 12:57 UTC ( #1051424=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Problems w/ encoding in terminal
in thread Problems w/ encoding in terminal

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.

لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re^3: Problems w/ encoding in terminal
Select or Download Code
Re^4: Problems w/ encoding in terminal
by humble (Acolyte) on Aug 30, 2013 at 05:23 UTC
    Awesome! Thank you exceedingly much!
Re^4: Problems w/ encoding in terminal
by humble (Acolyte) on Aug 30, 2013 at 15:05 UTC

    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?

      Without seeing the contents of the file, I cannot tell, but it seems it contains some bytes that are not UTF-8.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        Exactly! I apologise exceedingly! -- I was watching my files' content encoding always, but this time i missed it. Please pardon me!

        Now, how do i tell PERL to warn me on opening non-UTF8 file's content?

        I used:

        use utf8::all; open $fh, '<', $file || die "sopen: Cann't open $file $!"; binmode $fh, ':encoding(UTF-8)'; do{ $cont.=<$fh>; }until( eof( $fh ) ); close $fh;

        But it keeps saying:

        utf8 "\xB4" does not map to Unicode at ...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-08-21 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls