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

Hi Monks

I'm trying to handle some values from a text file in Perl, but it's having a problem with what I think is a UTF-8 middle decimal point (U+00B7 - ·).

Unpacking it gives me 194183.

map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk

Replies are listed 'Best First'.
Re: Encoding Problem - UTF-8 (I think)
by choroba (Cardinal) on Dec 15, 2015 at 16:52 UTC
    Without seeing the script, it's hard to tell, but I'd guess you failed to specify the encoding layer when opening the file:
    open my $FH, '<:encoding(UTF-8)', 'filename.txt' or die $!; # ~~~~~~~~~~~~~~~~

    Unpacking how? There are various templates you can use.

    Update:

    Yes, that's it:

    #! /usr/bin/perl use warnings; use strict; use feature qw{ say }; use Encode; my $s = encode('UTF-8', "\N{MIDDLE DOT}"); say join ' ', unpack "C*", $s;
    ($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,

      I unpacked with "unpack ('C*', $_);"

      Hmm... in Notepad++ when the encoding is set to utf-8, it looks okay (a weird floating decimal point), but if I switch to ansi, then I see circumflex A + weird decimal point, which is what perl is outputting when it comes across this value.

      Sigh - I hate encoding issues - the IRQs of today.

      map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
      Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk
        I hate encoding issues - the IRQs of today.

        It's worse. IRQs are/were a necessary evil; Unicrap on the other hand is stupid by design.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.

      Hmm... well, I struggled to get perl to interpret the rogue characters in a meaningful way, but this regex fixed them:

      $value =~ s/\302\267/\./;
      map{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
      Tom Melly, pm (at) cursingmaggot (stop) co (stop) uk