in reply to using online translation engines with perl
you can have exotic utf8 values without use utf8;, but not variable names.Note that the "exotic" (non-ASCII) values would be slightly different in those cases. If you don't use utf8;, you get a string scalar consisting of exactly the bytes that happened to be in the file you saved. (They can mean some text in UTF-8, or KOI8-R, or Shift JIS or nothing at all.) If you do use utf8;, Perl automatically decodes the string you'd typed from UTF-8 into Unicode characters. You can notice the difference if you use Dumper or length on the strings:
# Dumper prints character codes for wide characters
$ perl -MData::Dumper -Mutf8 -E'print Dumper "привет"'
$VAR1 = "\x{43f}\x{440}\x{438}\x{432}\x{435}\x{442}";
# Dumper prints bytes, and I get exactly what I'd typed
$ perl -MData::Dumper -E'print Dumper "привет"'
$VAR1 = 'привет';
# byte-string consists of 12 bytes of UTF-8
$ perl -MData::Dumper -E'say length "привет"'
12
# character-string consists of 6 wide characters
$ perl -MData::Dumper -Mutf8 -E'say length "привет"'
6
(Using <pre> because PM engine encodes all non-ASCII characters into HTML entities and <code> doesn't let them be interpreted.)
Every subsequent time, it fails, and $! is stone silent.Documentation examples show that you are supposed to look for the error in $sftp->error, not $!.
The functionality I would like to add are conditions such that if a translate call hangs, I can get to the next one, so what I'm fishing for is code that would go the next in the for loop if it lasts for, say, a minute.For a really primitive timeout implementation, see alarm. If you need more fine-grained control, threads with Thread::Queue might be a good solution.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using online translation engines with perl
by Aldebaran (Curate) on Nov 07, 2018 at 00:56 UTC | |
by Anonymous Monk on Nov 07, 2018 at 07:25 UTC |