develooper Front page | perl.unicode | Postings from July 2010


Thread Next
Dan Muey
July 29, 2010 14:59
Message ID:
Hello all,

I've a situation where a large code base will be outputting "byte strings" and "unicode strings" from a number of sources.

I essentially need to do 
     no warnings "utf8";
but I need to do it one time and globally instead of limiting to a package or some scope.

Is there a way to have the same effect as "no warnings 'utf8';" universally without the need to do it in every package and scope?

Here is a simplified version of the problem:

[ -- Problem: Unicode string gives warning -- ]

    perl -le 'print "Think before you code™ (bytes string)";print "Hello \x{201C}World\x{201D} (Unicode String)";'

adding either of these doesn't change the effect:

   $ENV{LC_CTYPE} = "UTF-8";

[ -- Partial solution but new problem: Warning goes away but byte string has garbled trademark character -- ]

    perl -le 'binmode STDOUT, "utf8";print "Think before you code™ (bytes string)";print "Hello \x{201C}World\x{201D} (Unicode String)";'

    PERL_UNICODE=6 perl -le 'print "Think before you code™ (bytes string)";print "Hello \x{201C}World\x{201D} (Unicode String)";'

[ -- this  has no warning and no garbled characters but it is impractical to impossible to do the pragma everywhere ti might be necessary  -- ]

    perl -le 'no warnings "utf8";print "Think before you code™ (bytes string)";print "Hello \x{201C}World\x{201D} (Unicode String)";'

[ -- ideal solution -- ]

Since we use our localization module everywhere that will have \x{} notationo I'd like to do whatever needs done in its begin block.

Is there any super voo doo that can be done?

Thanks in advance for any input!

Dan -
Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About