Keep It Simple, Stupid PerlMonks

### Comment on

 ( #3333=superdoc: print w/ replies, xml ) Need Help??
Your dec has a problem. Anything matched by /^[0-7]+\$/ or /^\d+\$/ is going to be matched by /^(0x)?[0-9A-Fa-f]+\$/i as well, so if you do the tests in order you present it, it'll assume either hexadecimal, or binary. Reversing the order will give a problem as well. How would you distinguish between 1016 == 1610, 1010, and 108 == 810 (subscripts indicate base)?

Of course, as pointed out, your fallacy lies in assuming that oct and hex return decimal representations of numbers - they don't. They return numbers:

```    \$ perl -MDevel::Peek -wle 'Dump hex 10'
SV = IV(0x8192014) at 0x8181270
REFCNT = 1
IV = 16
It's a number - without a stringified valued.

Also, Perl already has a function to turn a number into a hexadecimal, octal or binary representation: it's called sprintf.

Abigail

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.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2016-05-24 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
What font do you use for programming?

Results (315 votes). Check out past polls.