in reply to Re^2: Hex to decimal resulting in integer overflow (inc hex regex)
in thread Hex to decimal resulting in integer overflow

Cool, thanks for sharing. I was actually looking for that solution, but just got a tooth extracted today and the brain just wasn't working right.

The 'g' modifier isn't actually necessary there, and adding 'i' lets you remove the upper case entries from the character classes. Of course, the hash lookup is as fast as you're ever going to get, but I'd still probably choose to do the functional solution.

sub incHex { s{ ( [0-9a-f] ) # Any hex digit followed by ( f* )\b # (always) trailing (optional) 'f's }{ sprintf("%x", 1 + hex $1) . '0' x length($2); }iex for @_; }

Very nice though

  • Comment on Re^3: Hex to decimal resulting in integer overflow (inc hex regex)
  • Download Code

Replies are listed 'Best First'.
Re^4: Hex to decimal resulting in integer overflow (inc hex regex)
by tye (Sage) on Apr 02, 2011 at 02:54 UTC

    Actually, the /g was quite intentional. If you are going to drop that, you might also want to change the \b to a $.

    Yes, my hash look-up is likely insignificantly faster. But your use of /i also likely leads to an additional (insignificant) performance penalty.

    Perhaps somewhat unfortunately, the computer science term "functional" means much more than "using functions". Perhaps you should use "procedural" instead? Or "function-based"?

    Thanks.

    - tye