merrymonk has asked for the wisdom of the Perl Monks concerning the following question:

This has to be simple!
I need to test driving a printer via the LPT1 port.
Unfortunately the printer is several thousand miles away so some things are a bit difficult.
After 'opening' the printer, the C line to output the 'starter' character is fputs (“\x02L\n”, stdaux)
Is the following the correct way of getting the same output with Perl
print PRN hex "0x02"; print PRN "L\n";

If not I would be grateful to know what is.
Many thanks in advance.

Replies are listed 'Best First'.
Re: Printing Hexadecimal Characters
by sauoq (Abbot) on Oct 19, 2005 at 16:32 UTC
    Is the following the correct way of getting the same output with Perl

    No. Don't over-think it. ;-) Try

    print PRN "\x02L\n";

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Printing Hexadecimal Characters
by ikegami (Patriarch) on Oct 19, 2005 at 17:11 UTC

    No, that prints "2L\n"

    In string literals, the C syntax works in Perl:

    print PRN "\x02"; # or "\x{02} if the next character is a hex digit. print PRN "L\n";

    or just

    print PRN "\x02L\n";

    If you start with a variable containing the number 2, you can use chr:

    print PRN chr(0x02); print PRN "L\n";

    or pack:

    print PRN pack('C', 0x02); print PRN "L\n";