in reply to Processing spreadsheet with some cells in ASCII, other cells in UTF-8
This is my first ever attempt at non-ascii processing, so I'll let the more experienced Monks criticize if this is the wrong approach, or if there's a better one.
After a very quick dig online, I found that setting binmode on all the file handles can fix the issue:
Input file:
$ cat in.txt }cýæu}*]…‘¦å hello ›ÇÁ
Code:
use warnings; use strict; open my $fh, '<', 'in.txt' or die $!; open my $wfh, '>', 'out.txt' or die $!; binmode $fh, ":utf8"; binmode $wfh, ":utf8"; binmode STDOUT, ":utf8"; while (<$fh>){ chomp; print $wfh "file: $_\n"; print "stdout: $_\n"; }
Output:
# output file file: }cýæu}*]…‘¦å file: hello ›ÇÁ # stdout stdout: }cýæu}*]…‘¦å stdout: hello ›ÇÁ
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Processing spreadsheet with some cells in ASCII, other cells in UTF-8
by Amphiaraus (Beadle) on Sep 02, 2015 at 19:31 UTC |