in reply to trouble printing spanish characters

Where are your Spanish characters actually coming from? A data file? A web page? User input? How much do you know about your input data? (E.g. would you be able to say or find out what character encoding is being used when the data first comes into your script?)

If you're getting "line drawing characters" at the printer, your script might be sending the characters as utf8, and in that case, using the Encode module (and its "encode()" function), as shown in the first reply, is likely to be the right way to go -- though actually, assuming that perl is initially storing your strings internally as utf8, something like this would be simpler:

binmode( PRN, ":encoding(cp437)" );
By setting a PerlIO layer on your PRN file handle to apply the character encoding transfor for you (from utf8 to cp437), you don't need to do anything else -- you don't need "use Encode", you don't need any substitutions or other alterations of your string data.

Your statement of the problem was vague enough that I can't be sure this is the right answer, but this is a place to start, at least.

Replies are listed 'Best First'.
Re^2: trouble printing spanish characters
by schweini (Friar) on Oct 22, 2005 at 00:38 UTC
    i'm getting the spanish characters via CGI, DBI or even hardcoded into the script - but those 'wrong' characters appeared even when i was just echoing to lpr from bash - looked fine on the screen, came out wrong on the printer.
    thanks a lot for the PerlIO suggestion - something like that was what i was looking for. I can't test it now, but i got a hunch that that was the problem. Thanks again.