Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"print $!" prints bad characters #9

Closed
olegwtf opened this issue Jan 14, 2012 · 8 comments
Closed

"print $!" prints bad characters #9

olegwtf opened this issue Jan 14, 2012 · 8 comments

Comments

@olegwtf
Copy link

olegwtf commented Jan 14, 2012

use strict;
use utf8::all;
use IO::Socket;

unless (IO::Socket::INET->new("localhost:1111")) {
        print $!, "\n";
}

On my system this program prints unreadable characters Ð Ñоединении оÑказано
My locale is ru_RU.UTF-8. At the same time die $!, "\n"; prints correct characters.

@Leont
Copy link
Contributor

Leont commented Jan 14, 2012

This sounds to me not like a bug in utf8::all but in perl itself. Perl has no idea it should interpret $! as UTF-8 or not, so decides to treat it like latin1.

@olegwtf
Copy link
Author

olegwtf commented Jan 14, 2012

Yes it looks more like Perl bug, because smth like perl -CS -MErrno -le '$!=Errno::ETIMEDOUT; print $!' has same behaviour.

Perl has no idea it should interpret $! as UTF-8 or not, so decides to treat it like latin1.
But I wondering why output looks correct when using warn or die?

@doherty
Copy link
Owner

doherty commented Mar 3, 2012

@Leont: Is there a workaround we could use for Perl's global variables like $!? Also, do you know if this bug has been reported to the tracker for core?

@Leont
Copy link
Contributor

Leont commented Mar 4, 2012

I think I forgot to report it, and I can't find it on rt either. I don't think there's an easy way of dealing with this, other than decoding $! explicitly

@doherty
Copy link
Owner

doherty commented Apr 3, 2012

@doherty doherty closed this as completed Apr 3, 2012
@Leont
Copy link
Contributor

Leont commented Apr 4, 2012

Is there a workaround we could use for Perl's global variables like $!?

Actually, I'm pretty sure it'd be possible to monkey-patch $! to lexically do the right thing. I've done something similar once for $< and friends.

@doherty
Copy link
Owner

doherty commented Apr 4, 2012

If you can dig it up, that could be useful for perls that don't have this issue fixed.

@Leont
Copy link
Contributor

Leont commented Apr 6, 2012

You can find it at https://github.com/Leont/utf8-errno. I haven't tested it at all beyond "it compiles" though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants