in reply to Re^3: PDF::API2 printing non ascii characters
in thread PDF::API2 printing non ascii characters

I'm scratching my head now with the code below:

#sometext is a web input my $line = uri_escape($sometext); # $line prints $VAR1 = 'Hello%20%CF%89%20%E2%88%9E'; $line = uri_unescape($line); # $line prints Hello ω ∞
instead of Hello ω ∞

What am I missing?

Replies are listed 'Best First'.
Re^5: PDF::API2 printing non ascii characters
by thanos1983 (Parson) on Mar 14, 2018 at 09:44 UTC

    Hello Anonymous Monk,

    Try something like that:

    #!/usr/bin/perl
    use utf8;
    use strict;
    use warnings;
    use URI::Escape;
    use feature 'say';
    use Encode qw/ decode /;
    binmode STDOUT, ':utf8';
    
    sub nonDecodedUri {
        return uri_unescape( shift );
    }
    
    sub decodedUri {
        return decode 'UTF-8', uri_unescape( shift );
    }
    
    say nonDecodedUri('Hello%20%CF%89%20%E2%88%9E');
    say decodedUri('Hello%20%CF%89%20%E2%88%9E');
    
    __END__
    
    $ perl test.pl
    Hello ω ∞
    Hello ω ∞
    

    Notice the comments of fellow Monk vr on his answer above.

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Thank you so much. Really appreciate all the solutions here :)))