Re: matchin # to alpha in perl
by "Srinivasan Ramakrishnan" <srinivar(at)md3.vsnl.net.in>
|
Date: |
Wed, 23 May 2001 20:05:37 +0530 |
To: |
"christopher l. filkins" <design(at)chronotope.com>, <hwg-languages(at)hwg.org> |
References: |
chronotope |
|
todo: View
Thread,
Original
|
|
Hi,
> I wrote this little routine in perl to match a number with it's
alphabetical
> space. Does anyone have a more elegant way to do this? TIA
>
> sub alpha {
> for ($randalph) { $header = /1/ && "a"
> || /2/ && "b"
> || /3/ && "c"
etc.,
<snip>
Why not do an ASCII comparison? A=65, Z=90, a=97 & z=122
So position of c?
26 - ( z - c)
26 - (122-99)
::or::
(c)- (a)+ 1
99 - 97 + 1
This has turned into more of a kludge than I originally envisaged, well
atleast you have a shorter routine here ;-)
-Srini
--
http://www.sriniram.com
http://symonds.net/~sriniram
HWG: hwg-languages mailing list archives,
maintained by Webmasters @ IWA