Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Generating characters (0 to 255)

by cmilfo (Hermit)
on Mar 27, 2003 at 20:23 UTC ( [id://246327]=note: print w/replies, xml ) Need Help??


in reply to Generating characters (0 to 255)

One Unix/Linux boxes, you can   man ascii    to print a table similar to those found in reference manuals.

Below is something I use to generate an ascii table when I'm not not on a *nix machine and don't have a book. It's pretty much the same as your code, just in the table format.

print "Decimal | Octal | Hex | Character\n"; print "--------+-------+-----+----------\n"; my @hs = (0 .. 9, 'A' .. 'F'); for my $r (@hs) { for my $c (@hs) { my $h = hex($r . $c); printf("%-8.8s\| %-6.6s\| %-4.4s\| %-s\n", sprintf("%u", $h), sprintf("%-3.3o", $h), sprintf("%-2.2X", $h), map({ s/\n/\^J/; $_ } sprintf("%c", $h))); } }

Update: Removed padding on last column per parv's suggestion below. Great idea!

Replies are listed 'Best First'.
Re: Re: Generating characters (0 to 255)
by tachyon (Chancellor) on Mar 28, 2003 at 00:23 UTC

    Of course you are going to way too much effort to do this....

    print "Decimal | Octal | Hex | Character\n"; print "--------+-------+-----+----------\n"; printf "%-8s| %03o | %02X |%3s\n",($_)x3,map{$_=/\n/?'^J':/\r/?'^M' +:$_}chr for 1..255;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Capture regularities in code, irregularities in data.
      my %c = ( map(+(chr,sprintf '\x%02X',$_), 0 .. 31, 127 .. 160), "\a" => '\a', "\b" => '\b', "\e" => '\e', "\f" => '\f', "\n" => '\n', "\r" => '\r', "\t" => '\t', ); print "Decimal | Octal | Hex | Character\n"; print "--------+-------+-----+----------\n"; printf "%7d | %03o | %02X | %4s\n", ($_)x3, $c{+chr}||chr for 1..25 +5;

      Makeshifts last the longest.

Re: Re: Generating characters (0 to 255)
by parv (Parson) on Mar 27, 2003 at 21:12 UTC

    I must say output of your program is much easier on the the eyes.

    Since the character is the last item to be printed in your program, number of spaces it takes could be omitted and still get left justified output by using just printf("%-8.8s\| %-6.6s\| %-4.4s\| %-s\n", ...). Otherwise, empty (unoccupied) spaces are printed after each character (which could potentially interfere w/ copy-paste). What do you think?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246327]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-16 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found