http://www.perlmonks.org?node_id=1051650


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

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?

Replies are listed 'Best First'.
Re^5: Problems w/ encoding in terminal
by choroba (Cardinal) on Aug 31, 2013 at 08:22 UTC
    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 ...

        Good time of the day.

        Also i wanted to ask, having used the pragma utf8::all, how do i process data that is not in unicode? - I have to save the result of the search by linux command "find" that gives my paths in unicode and non-unicode char.s. Have i to stop using the utf8 module for a moment and then enable and convert all the data to unicode - to work farther w/ it (like regexp-ing)? Or there are other ways?

        Alright, i guess i have better to start a new thread - as the original is complete long ago. :o)