How do I convert a string to base36 (0-9,a-z) in perl?
I want to convert IP addresses to base36 with a one to one map, so I can use them in a URL.
127.0.0.1
=== string ==> 127000000001 === base36 ==>
72.98.234.11
=== string ==> 072098234011 === base36 ==>
Isn’t base 10 good enough? That gives a number in [0-4294967295] (1 to 10 digits). That’s only slightly longer than what you we were going to get from your way (1 to 8 digits).
Completely reversible:
You could convert that number to another base other than 10 using any number of modules on CPAN.
Base 16:
Base 64: (This should be quite speedy. Faster even if ported to C.)