leszekdubiel has asked for the wisdom of the Perl Monks concerning the following question:

How to stop unicode warnings? Thank you :) :)

perl -e 'no warnings qw(utf8); use Path::Tiny; path("/tmp/malformeduni +code")->slurp_utf8' UTF-8 "\xA5" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xB3" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xF3" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xB3" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xA5" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\x8C" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xA5" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xF1" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xF3" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xEA" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801. UTF-8 "\xB3" does not map to Unicode at /usr/share/perl5/Path/Tiny.pm +line 1801.

Tried qw(UTF8), $PerlIO::encoding::fallback = FB_QUIET; ... no sucess

Replies are listed 'Best First'.
Re: Path::Tiny supress unicode warnings
by hippo (Archbishop) on Nov 15, 2022 at 11:20 UTC

    Why are you using slurp_utf8 if your input file is in some other encoding? Just use slurp instead and decode it yourself afterwards.


    🦛

Re: Path::Tiny supress unicode warnings
by 1nickt (Canon) on Nov 15, 2022 at 11:54 UTC

    Further to hippo's point, you can also specify the encoding as an option to slurp. From the doc to Path::Tiny :

    $data = path("foo.txt")->slurp( {binmode => ":raw"} );
    "Reads file contents into a scalar. Takes an optional hash reference which may be used to pass options. The only available option is binmode, which is passed to binmode() on the handle used for reading."

    Hope this helps!


    The way forward always starts with a minimal test.
Re: Path::Tiny supress unicode warnings
by soonix (Chancellor) on Nov 15, 2022 at 12:21 UTC
Re: Path::Tiny supress unicode warnings
by leszekdubiel (Scribe) on Nov 17, 2022 at 20:00 UTC

    Thank you for help. I will have to see deeper in documentation. :) :) :)