You are right -- all those codes do correspond to the ASCII table.
Very clever!! IE, yes it will work in all cases where the characters are part of the ascii table, which as moritz indicates is not all characters.
"use CGI" is generally the way to go tho. I've used this before, when I didn't want to use a module:
sub CGI_convert {
my @lut33 = ('!', '"', '#', '$', '%', '&', "'", '(', ')', '*',
+ '+', ',', '-', '.', '/');
my @lut58 = (':', ';', '<', '=', '>', '?', '@');
my @lut91 = ('[', '\\', ']', '^', '_', '`');
my @lut123 = ('{', '|', '}', '~');
my $flag = 0;
my $string = pop;
if ($string =~ /^%/) { $flag=1 }
my @ray = split /%/,$string;
foreach my $e (@ray) {
unless ($flag) { $flag=1; next };
my $dsym = hex(substr($e,0,2));
my $symbol = undef;
if (($dsym<48) && ($dsym>32)) { $dsym-=33; $symbol=$lu
+t33[$dsym]; }
if (($dsym<65) && ($dsym>57)) { $dsym-=58; $symbol=$lu
+t58[$dsym]; }
if (($dsym<97) && ($dsym>90)) { $dsym-=91; $symbol=$lu
+t91[$dsym]; }
if (($dsym<127) && ($dsym>122)) { $dsym-=123; $symbol=
+$lut123[$dsym]; }
unless (defined $symbol) { next };
substr($e,0,2)=$symbol;
}
return join "",@ray;
}
But Your formulation is considerably less long winded. Nice.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.