This uses transliteration to map a certain set of characters to
another set. The source set is comprised of the ASCII characters
from '0' to '>'. If you look at the source string, you'll notice that
it's comprised entirely of characters within the source set.
The tr takes the source set and maps it onto the destination
set, which is ' LEOR!AUBGNSTY'; for each character in the source
set, it gets mapped to the corresponding character in the dest
set. For example:
'0' => ' '
'1' => 'L'
'2' => 'E'
...
'>' => 'Y'
It's just like a substitution cipher (I think that's the right name).
You can do it manually: go through the source string, the
string in $_, which is
6110>374086;2064208213:90<307;55
and replace each character by the corresponding character in
the destination set. '6' is turned into 'A', '1' is turned into 'L', '1'
is turned into 'L', etc. And right there you have 'ALL'.
Make sense? The key point here is to know what tr does, so
you should read the docs for that if you're still not sure how
this works. | [reply] [d/l] [select] |
Well, sure, I can try.
The first part of the program, $_="6110>374086;2064208213:90<307;55"; simply puts a string with (seemingly) gibberish in $_. Then, the second statement, tr[0->][ LEOR!AUBGNSTY]; maps every character from 0 to > to the corresponding character in the second part of the transliteration statement ( LEOR!AUBGNSTY). Basically, the changes go like this:
Old | new |
'0' | ' ' |
'1' | 'L' |
'2' | 'E' |
'3' | 'O' |
'4' | 'R' |
'5' | '!' |
'6' | 'A' |
'7' | 'U' |
'8' | 'B' |
'9' | 'G' |
':' | 'N' |
';' | 'S' |
'<' | 'T' |
'>' | 'Y' |
That range occurs because of the - in the first section of the tr statement. Anyway, after that it gets printed. (print).
The -l on the command line forces the output to add a newline at the end of every output statement, if I'm reading perlrun right.
Hope that helps. I'm sure if I'm wrong we'll both find out pretty soon. :)
His Royal Cheeziness
| [reply] [d/l] [select] |
Although the other answers appear to explain the way
this works
they ignore one other trick going on here.
The ASCII characters between 0 and > inclusive
are 0 1 2 3 4 5 6 7 8 9 : ; < = and >.
You'll notice that the > character
was used in the example code, and not the
= charactor, though if you do
a one-to-one mapping it looks like = should
have been used, and
> would be left over.
The reason the could given still works is another bit of
magic -- when tr's replacement list is shorter then its
source list it duplicates the last item of the replacement
list to match, thus the Y at the end
correspondes to both = and >.
Except with some /something options: see
perlop for more information, of course.
| [reply] [d/l] [select] |
Thanks a lot for that everyone, that's certainly taught me something about tr// that I didn't know. The only way I knew how to obfuscate it was to do a y// instead...
| [reply] |
| [reply] |