in reply to Best way to put : between fields in a string

{ local ($,, $\) = (":", "\n"); print unpack 'A2A5A3A3A2', 'A3xyz45M98AB7Z9'; }

Works for me ;)

Replies are listed 'Best First'.
Re^2: Best way to put : between fields in a string
by piroufreek (Acolyte) on Apr 21, 2005 at 12:39 UTC
    I thought about doing it using fixed-length fields, but he seems to want to put a colon after each number followed by a letter (i.e. \d:[a-zA-Z]).

      Yeah, what did not surprise me was the fact that people jumped on to find "patterns" in the string etc. The question simply asked "Take string X and transform it into string Y". I have learned, as a life lesson, that second-guessing people is not always profitable, in fact it's not most of the times. Just give 'em what they want, with minimum complications. My post was intended for contrast.

      On a lighter side, I guess one could come up with an even more braindead solution (I'd investigate substr, index, for-a-la-C etc.)