A v-string, such as v65.66.67, is encoded as a character string with no special type designation. So, when given a parameter that might be a v-string or might be something else, how do you tell them apart?

I think I came up with an efficient and useful way:

I'll treat it as a v-string if it contains any characters in the range \0-\1F. Most v-strings will contain entirely values in that range anyway, and real words (including specifically version designators spelled out as ascii numbers and identifiers) will not contain non-graphic control codes. Maybe I'll leave out \t and \n and \r just to be safe.

Two key points to this: I can perform the check using the fast counting mode of tr; and more importantly a v-string that is not usual, like the one in the first sentence, can be distinguished by adding a trailing .0 which does not affect the meaning.

What do y'all think? Any better ideas?

—John


In reply to Distinguishing a v-string from something else by John M. Dlugosz

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.