To be honest, a description of what your cow-orker wants would be helpful, too. I prefer to write my solution in the language of the problem, rather than the language of the solution. It makes things more obvious later (and possibly, more robust when strange things happen).

For example, if you were to say that "Each set of letters followed by set of numbers is a token, and we want colons to separate our tokens," then, IMO, splitting the string into said tokens, and joining with a colon, as you did, seems to be the best way to me to do it.

But, if the requirement is, "I don't want numbers and letters to touch when the number is prior to the letter, so separate them with a colon," then I would suggest an alternate approach, such as s/(?<\d)(?>[[:alpha:]])/:/g.

The point is to really pay attention to what you really need, and to write the solution that matches.


In reply to Re: Best way to put : between fields in a string by Tanktalus
in thread Best way to put : between fields in a string by eyepopslikeamosquito

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.