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

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

Thread Next
From:
Karen Etheridge
Date:
March 24, 2016 23:15
Subject:
[perl #127780] documentation needed: backticks, qx() return octets,not characters
Message ID:
rt-4.0.18-32413-1458861300-1308.127780-75-0@perl.org
# New Ticket Created by  Karen Etheridge 
# Please include the string:  [perl #127780]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=127780 >


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.

Therefore:

    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.";

...is 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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About