I am trying to read data produced by another program (dumptorrent) through a pipe. If I set binmode ":encoding(UTF-8)" on the pipe, data containing the character '–' is read correctly, but the character '·' is not. If I omit the binmode call, the '·' character is read correctly, but the '–' character is not. How do I read this data correctly?

Thanks

use strict; use warnings; my $linecount = 0; open(DATA, qq(dumptorrent.exe "$ARGV[0]"|)); #binmode(DATA, ":encoding(UTF-8)"); binmode(STDOUT, ":encoding(UTF-8)"); foreach my $line (<DATA>) { # Discard the 5 lines of output before the list of filenames if (++$linecount > 5) { chomp $line; last if (length($line) == 0); $line =~ s/^ *//; $line =~ s/ +\([\d.]+[KMG]\)$//; # e.g. (8.22M) present fo +r files larger than ~1k; discard it my $sizeindex = rindex($line, ' ') + 1; my $filesize = substr($line, $sizeindex); # Ignore zero-length files in torrents. if (defined $filesize && length($filesize) > 0 && $filesiz +e > 0) { (my $filename = $line) =~ s/ +\d+$//; my $filekey = "$filename $filesize"; print "$filekey\n"; } } }

In reply to What is the proper way to read non-ANSI data by freonpsandoz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.