Clear questions and runnable code
get the best and fastest answer
Split int into segments of max int 26by thanos1983 (Parson)
|on Sep 12, 2017 at 23:33 UTC||Need Help??|
thanos1983 has asked for the wisdom of the Perl Monks concerning the following question:
Hello fellow Monks,
I am trying to translate int to ASCII (alphabetical) characters. I am having as an input int e.g. 1 - 26 everything works just fine.
My problem occurs in case that I am having an int as e.g 27, then if I translate this int + 64 (decimal base) to ASCII it comes as [ which of course is the correct translation for int 91.
I am trying to think of a way of splitting the int into segments with max int 26. I mean for example if int is 27 or greater somehow split the int into 26 and 1.
My progress so far is almost to zero, because I can not think any way of doing such a process, since the number can increment to "theoretically" max int. So my goal is to create a generic solution.
Sample of code to represent the problem / solution and how I encode / decode the int:
In my case I am using the chr function to translate the characters. For example I am using my $character = chr(64+$i). This works just fine as long as the int is bellow 26 after that I am getting the ASCII non alphabetical characters that I can not use.
To avoid confusion why I am trying to translate int to characters. I have a script that is reading and writing excel files and the columns e.g. (A-Z) are just fine for writing (where the problem occurs) but as soon as I need to write a column e.g. (AA) then I am having problems.
The error from my other script is:
I debug the script and I found the problem:
I am not posting the code here as it is irrelevant and will only consume space, the problem that I am trying to resolve is to split int with max value 26 so I can translate them to ASCII alphabetical characters. In case that anyone wants to play around with the code here is the code Re: Merging 2 xlsx files.
Any ideas, are appreciated. Thanks in advance for the time and effort.
Seeking for Perl wisdom...on the process of learning...not there...yet!