use CGI;
use HTML::Entities;
use URI::Escape;
my $q = CGI->new;
my $data;
my $toggle = initToggle( 1 );
for my $ASCII ( 0 .. 255 ) {
# The following is a hexadecimal list of characters that must be encoded
# in query strings
my $cgi_chars = '\x00-\x29\x2b\x2c\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\xff';
# The following is a hexadecimal list of characters that often have their
# HTML character code equivalent used instead of the characters themselves
my $html_chars = '\x00-\x2f\x3a-\x40\x5b-\x5e\x60\x7b-\xff';
my $char = chr( $ASCII ); # The actual character
my $symbol = encode_entities( $char, $html_chars ); # HTML code for Web page
my $escaped = uri_escape( $char, $cgi_chars ); # CGI representation
my $html_code = encode_entities( $symbol ); # Re-encode HTML code so that it
# displays properly
if ( $escaped eq '%20' ) { $escaped .= ' or +' }; # a space may be %20 or a +
my @bgcolor = ( '#FFFFFF', '#CCCCCC' );
$data .= $q->Tr( { -align => 'right',
-bgcolor => $bgcolor[ &$toggle ] },
$q->td(
[ $ASCII < 33 ? ' ' : $symbol, $ASCII, $escaped, $html_code ]
)
);
}
print $q->header,
$q->start_html,
$q->table( $data ),
$q->end_html;
sub initToggle {
my $limit = shift;
my $count = 0;
my $bit = 0;
unless ( $limit > 0 ) { die "initToggle() requires a positive argument\n" };
return sub {
$bit ^= 1 if $count++ % $limit == 0;
}
}