Perl - convert string to number question
I'm a little confused and wondered if any AO'ers could clarify this issue for me. I've found a few references via google search but either they aren't what I'm looking for or I simply don't understand that they are what i'm looking for. And section 2.3.4 of the llama book isn't very clear on the matter.
my question is simple: In Perl, can I convert a single letter to it's alphabetic numeric equivalent? Meaning, 'a' would equal '1' and so forth.
a sample prog that illustrates this idea would be:
print "Give me a letter: ";
$letter = <>;
print "Give me a number: ";
$num = <>;
print $letter + $number;
So, if i gave 'a' as the letter and 1 as the number, the prog would print '2' as the answer.
Any thoughts or hints? Or am I reaching and it would be better to build a database table or hash that contained the letter-number mappings?
Thanks in advance.
re: letter, number equivalents
To clarify, what I mean is that in the english alphabet we have 26 letters. If we were to number them, a=1, b=2...z=26.
I'm interested in methods to make perl recognize this process in order to convert letters to digits, then perform various operations between numbers, then even convert digits back to letters once the operative manipulations are complete. This is mainly for basic cryptographic hobbying...
I'm not a Perl expert by far, but it doens't seem that Perl will 'natively' recognize the english alphabetic relationship that I'm describing. So, would it be better to build a database or even a Perl hash to hold this data?
If i'm not being clear, i sincerely apologize. Like i stated, I'm just a little confused on how or what would be the best method to construct this letter-number relationship in Perl.
I do appreciate your comments HTRegz. I hope my clarification above helps...