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:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; my @characters = ("Z", "["); my %hash; for ( @characters ) { my @ascii_character_int = unpack("C*", $_); $hash{$_} = \@ascii_character_int; my $word = pack("C*", @ascii_character_int); say $word; } print Dumper \%hash; __END__ $ perl test.pl Z [ $VAR1 = { 'Z' => [ 90 ], '[' => [ 91 ] };

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:

Unknown cell reference [1

I debug the script and I found the problem:

Column Index: 27 Column Character: [ Text: Test Line at AA

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!

In reply to Split int into segments of max int 26 by thanos1983

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.