hbm has asked for the wisdom of the Perl Monks concerning the following question:

I'm intrigued by the different results below:

perl -e 'print "\x{01C1}\n";' Wide character in print at -e line 1. Ç perl -e 'warn "\x{01C1}\n";' Ç perl -e 'die "\x{01C1}\n";' Ç perl -e 'print STDERR "\x{01C1}\n";' Wide character in print at -e line 1. Ç

I would have thought 'warn' and 'die' did essentially 'print' to STDERR...

Replies are listed 'Best First'.
Re: can 'warn' but not 'print' wide character
by ikegami (Patriarch) on Sep 13, 2010 at 20:28 UTC
    Maybe it was thought that warning about a warning would just add confusion? Or maybe it was just overlooked.

    I would have thought 'warn' and 'die' did essentially 'print' to STDERR...

    It does use STDERR, but the print opcode is not involved.

Re: can 'warn' but not 'print' wide character
by Khen1950fx (Canon) on Sep 13, 2010 at 23:36 UTC
    I took a slightly different path. Maybe you were looking for something like this?
    #!/usr/bin/perl use strict; use warnings; binmode STDERR, ':encoding(utf8)'; print STDERR "\x{01b1}\n"; binmode STDOUT, ':encoding(utf8)'; print "\x{01b1}", "\n"; warn "\x{01b1}", "\n"; die "\x{01b1}", "\n";
Re: can 'warn' but not 'print' wide character
by Anonymous Monk on Sep 13, 2010 at 20:02 UTC
    I would have thought 'warn' and 'die' did essentially 'print' to STDERR...

    Yes, essentially, but no, they don't call print

Re: can 'warn' but not 'print' wide character
by ikegami (Patriarch) on Sep 16, 2010 at 13:36 UTC
    Turns out there was an outstanding ticket for this, and it just got resolved.

      What timing! Are you in on that bug system? I believe 'die' needs the same fix.

      This code from the bug report:

      perl -we '$a="\xee\n"; print STDERR $a; warn $a; utf8::upgrade($a); pr +int STDERR $a; warn $a'

      gives the same results as this:

      perl -we '$a="\xee\n"; print STDERR $a; die $a;' perl -we '$a="\xee\n"; utf8::upgrade($a); print STDERR $a; die $a'

      Thanks!

        I don't know if it was fixed by the same patches or by different patches, but die() will warn too in 5.14.

        $ ./perl -v This is perl 5, version 13, subversion 4 (v5.13.4-312-g6e4e365) built +for i686-linux ... $ ./perl -e'warn chr 300' Wide character in warn at -e line 1. Ĭ at -e line 1. $ ./perl -e'die chr 300' Wide character in die at -e line 1. Ĭ at -e line 1.