in reply to Re: UTF8 error when using Net::SFTP::Foreign
in thread UTF8 error when using Net::SFTP::Foreign

I think ikegami's point is that the byte sequence won't change if all you do is turn off the utf8 flag, and it seems like that is the only issue that Net::SFTP::Foreign is having with the OP data. Consider:
use strict; use warnings; main(); sub main { my $test = "\x{0414}"; # unicode cyrillic "capital letter de" printf( "character length: %d\n", length( $test )); check_string( $test, 1 ); # this call causes "Wide character in print" warning, but outpu +t is ok utf8::encode( $test ); printf( "byte length: %d\n", length( $test )); check_string( $test, 2 ); # no warning from this call } sub check_string { my ( $str, $num ) = @_; my $status = ( utf8::is_utf8( $str )) ? 'utf8' : 'not utf8'; printf( " %d -- check_string: input %s is %s\n", $num, $str, $stat +us ); }
When I have that stored as "test.pl" and do perl test.pl, the output I get is:
character length: 1
Wide character in print at /tmp/test-bytes.pl line 21.
 1 -- check_string: input Д is utf8
byte length: 2
 2 -- check_string: input Д is not utf8
Of course, if I run that with perl -CS test.pl (to do the same thing as  binmode STDOUT, ":utf8";), the "Wide character in print" warning goes away, but then when check_string() gets called the second time, perl forces an "upgrade" of the two bytes that make up the "unflagged" cyrillic character, producing faulty output (four non-ascii bytes instead of two) - but that's a separate issue.

Replies are listed 'Best First'.
Re^3: UTF8 error when using Net::SFTP::Foreign
by ikegami (Patriarch) on Feb 18, 2009 at 04:17 UTC

    I think ikegami's point is that the byte sequence won't change if all you do is turn off the utf8 flag,

    My point was simply that the solution doesn't depend on knowing whether the flag was on for a good reason or not.

    I have now elaborated on the solution.