Most likely, you'll need to change the text encoding before you print it. The Linux codepage is configurable, though iso-8859-1 is probably most common in English speaking countries.
Going to a Samba share, you'll likely need to re-encode the string into codepage 437; the standard DOS code page.
use Encode;
my $string = 'αινσϊ ρρρρ';
my $enc_string = encode('cp437', $string);
print PRN $enc_string;
| [reply] [d/l] |
That might not work, depending on the particular editor (locale, whatever) that is being used to write the perl script. If it doesn't save those accented characters as utf8, the assignment to $string -- or rather, the encoding of $string into cp437 -- will fail.
| [reply] |
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. | [reply] [d/l] |
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.
| [reply] |