Hello, So I have a script written to do a simple conversion of taking user input in the format of ##:## where the # are in place of a of a number of 0-9 or a letter of A-F (exception of not having the letter E in there) and calculating its hex value then adding one to it, and repeating for a amount specified by the user. The section of code relevant is
#takes the first two characters and stores them for later $AddressOriginal = substr($Address, 0, 3); #removes the first three characters leaving the later ## in the format + ##:## $Address = substr($Address, 3, 2); #Test lines to make sure the above lines do their intended purpose #print $Address . "\n"; #print $AddressOriginal . "\n"; for($count = 1; $count <= $IDcount; $count++) { $hexval = sprintf("%02X\n", ($Address)); $Address++; $Address1 = ($AddressOriginal . $hexval); #Test line to make sure the procedure completed its intended task print $Address1;
I have encountered a bug where when the user puts in a value with a letter in it of the second half of ##:##, it starts at 00. For example, Say I go and I pass it 3F:13, the next iteration would be 3F:14, 3F:15, 3F:16... However say I pass it A7:F0, we would expect it to go A7:F1, A7:F2, A7:F3... however it instead goes A7:00, A7:01, A7:02... I have already did several google searches, and looked into perldocs, however I am having trouble finding anything to be able to help me. The closest I have found is that perl assumes that whenever a user puts in a character such as F or B, that it makes it a string. I have already tried, having it be taken more clearly as a decimal I believe, by having the user put in two separate values, but nothing changed. Could anyone please point me in the right direction on where I may be going wrong, or explain to me where I have messed up?

In reply to Invalid Hex Conversion? by tfredett

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.