in reply to Read and write UTF-8
Here is an example:
#!/usr/bin/perl use Encode qw/encode decode/; open (INFILE, "< :encoding(UTF-8)", "utf8.txt") || die "blah blah blah +"; open (OUTFILE, "> :encoding(UTF-8)", "oututf8.txt") || die "blah blah" +; while (<INFILE>) { $line = $_; chomp ($line); $linestart = substr($line,0,20); $outline = "First 20: "."$linestart"; print OUTFILE "$outline\n"; } close (INFILE);
Actually this one reads and writes the non-ASCII characters, but when there is a non-ASCII character in the record it doesn't count the correct # of characters.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Read and write UTF-8
by Corion (Patriarch) on Oct 15, 2016 at 07:57 UTC | |
by choroba (Cardinal) on Oct 15, 2016 at 08:26 UTC | |
|
Re^2: Read and write UTF-8
by hippo (Archbishop) on Oct 15, 2016 at 08:52 UTC | |
|
Re^2: Read and write UTF-8
by Norah (Novice) on Oct 15, 2016 at 17:30 UTC | |
by Corion (Patriarch) on Oct 15, 2016 at 18:15 UTC | |
by Anonymous Monk on Oct 17, 2016 at 17:15 UTC | |
by Corion (Patriarch) on Oct 17, 2016 at 17:28 UTC | |
|
Re^2: Read and write UTF-8
by Norah (Novice) on Oct 14, 2016 at 23:19 UTC |