Dr. Mu has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a Perl/Tk (ActivePerl 8.4/WinXP) app that requires the display of negative numbers. The minus sign (-) seemed a little anemic, so I decided to replace all occurences of it with an n-dash (–), using the substitution s/-/\x96/g . The substitution occurs okay; however I don't get an n-dash, but rather a thick vertical bar. I tried other fonts: same result. Exploring further, I discovered that Tk displays the same vertical bar in all fonts for characters "\x80" to "\x9f", even though those fonts clearly include normal characters in that range. Beyond "\x9f" things return to normal.

So what's going on here? Is it a bug? Some Unicode thing I haven't yet grasped? I'm at a loss.

Update: Fixed HTML formatting error in n-dash literal.

Replies are listed 'Best First'.
Re: Perl/Tk Font Weirdness
by tachyon (Chancellor) on Nov 14, 2004 at 23:20 UTC

    Short answer make the - bold.

    Long Answer: On the Windows platform, ascii font mappers and the windows operating system default to using the Windows 1252 codepage (in the US) within the font and other Windows specific codepages elsewhere in the world. The Windows 1252 codepage has gyyphs associated with the characters associated with \x80 - \x9f, however, this range is usually reserved for control characters.

    It appears that Tk is (correctly) not mapping to Windows 1252 (because it is platform independent). Most likely Tk is mapping to the UniCode pages for Basic Latin (for hex 20-7F) and the Latin Supplement (for hex 80-FF). The code pages for Latin Supplement do not support hex 80-9F, thus your problem.

    cheers

    tachyon

Re: Perl/Tk Font Weirdness
by jdalbec (Deacon) on Nov 14, 2004 at 23:01 UTC
      Yup, the "use encoding cp1252';" works in Windows, and I get the n-dash I was after. But as tachyon points out below it's not portable, so no dice in Linux. Since this app gets ported to Linux later, I'll either have to be happy with the (already boldface) minus sign, or throw in some OS detection so the Windows port, at least, will look the way I want it to.
Re: Perl/Tk Font Weirdness
by paulbort (Hermit) on Nov 15, 2004 at 18:39 UTC
    Other options for making negative numbers more obvious include changing the foreground color to red and/or putting (parentheses) around the number. Both are common in various accounting applications.

    --
    Spring: Forces, Coiled Again!