Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Congratulations to the last person who voted this simple request down. I've had it with the trolls, votebots, and general decline of civilization of PM. I'm outta here.

Updated: Apparently, some people are dim enough to think this is a 'do my homework' type node. It's not. It's code for a future PM-related utility. I'm looking for a little help for something I'd rather not write if it already exists. I think it's called 'Not Reinventing The Wheel'.

I'm looking for some code that will do multi-base number verification. Here's the criteria:

  • A value passed in will have no leading, trailing or embedded spaces.
  • A base qualifier may have a leading '0x' to indicate hex, a trailing 'h' (upper or lower case) to indicate hex, a trailing 'o' (letter, upper or lower case) to indicate octal, or a possible trailing 't' (upper or lower case) to indicate decimal.
  • Numbers with no base qualifiers may be presumed to be decimal.
  • Scientific notation is a valid format, i.e. 14E+12 (the 'E' can be upper or lower case).
  • 0xffffh is not valid as a hex number, since it contains two qualifiers.
  • Hex and octal numbers may not contain decimal points.
  • The routine should return a flag indicating if the passed value was a syntactically valid number according to the rules, the base of the detected number, and the value of the number.
  • Must run under Perl 5.005 or higher. No 5.6.1+ specific solutions are acceptable.

Ideally, some large esoteric module should not be required. For instance, Parse::RecDescent with a grammar for number parsing is a sub-optimal solution.

I don't really care if it's an elaborate (fool-proof) regexp, a state machine, or pirated-and-ported VB code, as long it's solid.

Anyone got one of these handy, or want to golf one?


e-mail jcwren

In reply to Extract numbers in multiple bases by jcwren

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, 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:
    & &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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (5)
    As of 2018-04-22 05:27 GMT
    Find Nodes?
      Voting Booth?