Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: Malformed UTF-8 character Error

by ikegami (Pope)
on May 11, 2010 at 23:25 UTC ( #839519=note: print w/replies, xml ) Need Help??

in reply to Malformed UTF-8 character Error

UPDATE: I'd really just be interested in skipping line if it is not UTF-8, or not dealing with these lines at all.

Do you realize that you'd be skipping all four lines you posted since none are valid UTF-8?

It's easy to do:

use strict; use warnings; use open ':std', ':locale'; use Encode qw( ); my $log = 'log'; open(my $fh, '<:raw:perlio', $log) or die("Can't open log file \"$log\": $!\n"); while (<$fh>) { s/\r?\n\z//; my $data = (split(/ /, $_, 4))[3]; my ($text) = eval { decode("UTF-8", $data, Encode::FB_CROAK) } or next; print($text); }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839519]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-07-20 05:17 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (424 votes). Check out past polls.