develooper Front page | perl.perl5.porters | Postings from August 2008

[perl #58218] backwards logic in perluniintro (5.10.0)

Thread Next
From:
Brad Baxter
Date:
August 22, 2008 14:14
Subject:
[perl #58218] backwards logic in perluniintro (5.10.0)
Message ID:
rt-3.6.HEAD-29759-1219341743-316.58218-75-0@perl.org
# New Ticket Created by  Brad Baxter 
# Please include the string:  [perl #58218]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58218 >


-- Perl 5.10.0 documentation --
http://perldoc.perl.org/perluniintro.html#Questions-With-Answers

How Do I Detect Data That's Not Valid In a Particular Encoding?

Use the Encode package to try converting it. For example,

    use Encode 'decode_utf8';
    eval { decode_utf8($string, Encode::FB_CROAK) };
    if ($@) {
        # $string is valid utf8
    } else {
        # $string is not valid utf8
    }

Should be

    use Encode 'decode_utf8';
    eval { decode_utf8($string, Encode::FB_CROAK) };
    if ($@) {
        # $string is not valid utf8
    } else {
        # $string is valid utf8
    }

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