Randal L. Schwartz wrote:
>>>>>> "Andrew" == Andrew McFarland <[EMAIL PROTECTED]> writes:
> 
> Andrew> Wide character in print at /usr/lib/perl5/Template.pm line 168
> 
> For some reason, when I see that message, I always wonder if I've
> used the "w" character too much, or something.
> 
> "Dude - use narrower letters!"
> 
> :-)

Everybody makes fun of 'w' just because it gained a few pounds since its 
younger monospace years.

Andrew, what encoding is your data and output using? This is a classic error 
message I've seen related to utf8 encoding issues.

So for example if you have utf8 character data (with a symbol like a trademark 
or right/left quote) in $printme and you do:
print $printme. You will probably get this message.

Some work arounds I believe are to do either:
binmode STDOUT, ":utf8"; # tells stdout that your data is utf8 encoded 
characters

or I think you can do
print Encode::encode_utf8($printme) # converts perl utf8 into octet for output

It really depends on your data and output, though.

The Encode module is a good read for this sort of stuff:
http://search.cpan.org/~dankogai/Encode-2.23/Encode.pm

It's useful to note the difference in their terminology between octets, bytes, 
and characters under TERMINOLOGY. Here it is:

* character: a character in the range 0..(2**32-1) (or more). (What Perl's 
strings are made of.)
* byte: a character in the range 0..255 (A special case of a Perl character.)
* octet: 8 bits of data, with ordinal values 0..255 (Term for bytes passed to 
or from a non-Perl context, e.g. a disk file.)


Basically when you use Encode::encode you are converting to octets. (Just your 
standard 8 bits of data.) When you use Encode::decode you are converting from 
octets (8 bits of data) to characters that may utilize multiple octets. In the 
Encode::encode case your single unit is an octet. In the Encode::decode case 
your single unit will be a character which may be multiple octets. I believe 
this latter case is where the 'wide' character comes from. (Because you are 
trying to print to something that has a single unit of an octet, but your 
data's single unit is a character with more than one octet.)

Mihai's example was good. He used decode to make the single unit a utf8 
character (composed of octets) so perl could work on utf8 characters rather 
than only 8 bits of data. Then when he was done and ready to output he used 
::encode to convert the single unit back to just octets for output.

This patch work is how all this jives in my mind. I hope I'm not too wrong, 
because I'm sure more than one person will speak up. :P Even worse would be if 
Randal told another joke. ;)

-- Josh

_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to