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";
}
}
}