develooper Front page | perl.perl5.porters | Postings from March 2016

[perl #127780] documentation needed: backticks, qx() return octets,not characters

Thread Next
Karen Etheridge
March 24, 2016 23:15
[perl #127780] documentation needed: backticks, qx() return octets,not characters
Message ID:
# New Ticket Created by  Karen Etheridge 
# Please include the string:  [perl #127780]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is not surprising when you think about it, but it's a subtle gotcha that can cause a lot of bugs.  Any content that is fetched via the backtick operators or qx() comes back as *encoded octets* (since it's just a readpipe), and the user might need to decode it first to get a readable string.


    use utf8;
    my $str = "Les hivers de mon enfance ├ętaient des saisons longues, longues."
        . `bin/chandail --stanza 2`
        . "mais la vraie vie ├ętait sur la patinoire."; going to result in a garbage string, because utf8-ENcoded octets will be
mixed in with utf8-DEcoded characters.  One needs to wrap a decode('UTF-8',
...) around the output of the command!

We should really mention this in perlop.pod.

(and then later, in the documentation for IPC::System::Simple, Capture::Tiny, etc...)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About