Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks -doing a print to file and getting these characters … where I still should be getting good data. I tried a UTF8 print with no luck. Any suggestions?

open ($fh, ">>:utf8",.....

Thanks!

Replies are listed 'Best First'.
Re: strange characters in file City , CA …
by choroba (Cardinal) on Apr 04, 2017 at 08:00 UTC
    How did you get the data? If they come from an input, have you opened it with <:encoding(UTF-8) or whatever encoding they have? If they come from the script as literals, have you specified utf8?
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re: strange characters in file City , CA â&#128;¦
by huck (Prior) on Apr 04, 2017 at 08:01 UTC

    For that to work right you have to indicate that the data you are printing is proper utf8 "characters". I suspect you are reading bytes, not "characters", and so are still printing bytes.

    I get confuxed about all this too. But to take bytes and make them valid utf8 "characters", i do this (i think)

    use Encode; $contentutf8= Encode::decode_utf8($content);
    It would help if you showed us how you are getting the data you are printing, and an example of the bytes in question.