You are not logged in.
I was curious about Perl today so I started reading a tutorial and before you knew it I had pretty much wrote a small Caeser Cipher program. The only thing I can't figure out is how to shift the ascii characters in the array.
I tried to do it "C" style by adding +1 to the character array index for a +1 shift ("a" +1 = "b"), but apparently Perl doesn't like it, or I didn't use the correct syntax.
Is there any way to do this or am I going to have to use another method? I don't really need to do this program or anything, but trying to get some of the quirks down,
I really like what I have seen so far, really quick to pick up and feels very powerful.
Last edited by Google (2010-12-09 17:38:05)
Offline
There's probably a better way (i.e. a method that involves less typing on your part) but you could implement a hash that reads the input string 1 character at a time and outputs the corrected letter, and for any other non shifted input (whitespace and punctuations) just return themselves as values.
example:
my %cypher = (
"a" => "c",
"b" => "d",
"c" => "e",
...
...
"y" => "a",
"z" => "b",
" " => " ",
"." => ".");
Last edited by Cyrusm (2010-12-09 17:18:56)
Hofstadter's Law:
It always takes longer than you expect, even when you take into account Hofstadter's Law.
Offline
Interesting, I think this sounds like the easy way to go about something that was static. But, what about a shift that isn't static? If I enter 2 during one runtime and 5 the next I would need 26 hash tables?
Offline
I didn't read about those yet, thanks~ very interesting language!
Offline