March 3rd, 2004, 05:45 PM
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.
Ego is the great Logic killer