Nikos said:
Joe said:
Nikos said:
$toBeEncrypted =~ tr/a-zA-Z/b-zA-Za/;
a-z transletes to b-z
A-Z msut to B-Z why you say A-Za ?
If you use tr/A-Z/B-Z/ then Y translates to Z, but the character
that Z translates to is not specified. So either
tr/A-Z/B-ZA/
or
tr/A-Z/B-Z[/
is appropriate.
Your program should explicitly document what it does to
characters that are outside of the A-Z range.
Yes, now i think i understand. So the 'A' in tr/A-Z/B-ZA/ means that
every other character outside the A-Z range should be changes to A
No, lets make it clearer, in tr/A-Z/B-ZA/
1) The "A-Z" is shorthand for "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2) The "B-Z" is shorthand for "BCDEFGHIJKLMNOPQRSTUVWXYZ"
3) The final "A" just stands for "A"
4) From 2 and 3 we get "BCDEFGHIJKLMNOPQRSTUVWXYZA"
5) Each letter in the first string gets tranlated to the corresponding
position in the second string
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
to "BCDEFGHIJKLMNOPQRSTUVWXYZA"
So, for example "P" in the first string is translated to "Q" in the
second string.
AFAIK the order is unimportant[1] so it is exactly equivalent to
tr/QWERTYUIOPASDFGHJKLZXCVBNM/RXFSUVJPQBTEGHIKMAYDWCMO/
but that would be a pointlessly obscure way to write it.
Any character not matched in the first string is not altered in the result.
[1] so long as the strings are equal in length, and probably subject to
some other edge conditions I don't know about.