Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Converting "IV" from base 26

by Eimi Metamorphoumai (Deacon)
on Jul 01, 2008 at 14:29 UTC ( #694958=note: print w/replies, xml ) Need Help??


in reply to Re: Converting "IV" from base 26
in thread Converting "IV" from base 26

Your code works, but there's no reason to create (and pop from) the separate @letters array. Additionally, by doing the multiplication first, we can get rid of the $pwr variable, and get to the much simpler (to my mind, at least),
sub v { my $sum = 0; for (split //, $_[0]) { $sum *= 26; $sum += ord($_) - ord("A") + 1; } return $sum; }
You could also factor out the ord("A") + 1 part into a separate variable, but I think it's a little easier to read this way (and the cost of the extra calls to ord is probably negligible).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://694958]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2020-10-31 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (286 votes). Check out past polls.

    Notices?