[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] ASCII-07 and ASCII-08 As Raw Characters



Charley,

I don't see anything wrong with what you are doing.

The character set used by MacPerl console
will not print some of the characters;
one might print to a separate file or
cut&paste the output into a text display area using
Chicago 10-point (for example) to see more of the characters.
When I used BBEdit extension hex dump of cut-and-paste,
only 0x06, 0x07, and 0x08 had not transfered.

A few variants are below.

Charley Cowens thoughtfully keystroked:
>How do I get ASCII-07 and ASCII-08 to print to the console as uninterpreted
>bytes in a loop like this:
>
>for ($i=0; $i<=255; $i++) {
>        print pack("c",$i);
>}
>
>Binmode, naturally, doesn't make any difference, but neither does the `stty
>raw` command. (I have 5.1.9r4.)
>
>Thanks,
>Charley Cowens

A few different ways to obtain identical output:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!perl -w

print "All of the following yield same output:  \n";
print "\n\n Original version \n";

for ($i=0; $i<=255; $i++) {
        print pack("c",$i);
}

# "C" vs "c" seems to matter only to unpack(), not pack().

print "\n\n Original version with input wrapped to -128..127\n";

for ($i=0; $i<=255; $i++) {
        print pack("c",( $i > 127 ? $i - 256 : $i ));
}

print "\n\n Unsigned pack 'C' version \n";

for ($i=0; $i<=255; $i++) {
        print pack("c",$i);
}

print "\n\n printf(\"%c\") version \n";

for ($i=0; $i<=255; $i++) {
        printf("%c",$i);
}

# chr() is new to Perl V5.

print "\n\n chr() version \n";

for ($i=0; $i<=255; $i++) {
        print chr($i);
}

print "\n\n End of methods.\n";
__END__
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

--
Regards, Larry F. Allen-Tonar        (larryat@cts.com) +1 760/746-6464 (voice)
         Principal Software/Firmware Engineer          +1 860/746-0766 (FAX,
         RYLAR                                                   upon request)
         P.O. Box 463072
         Escondido, CA  92046-3072



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch