in reply to Re: List manipulation headache
in thread List manipulation headache

Interesting! Smart solution. Building on the excellent proposal by @elef, the expression can be further compressed to the following:
s/ wap([2-9])/,$1/g

Replies are listed 'Best First'.
Re^3: List manipulation headache
by elef (Friar) on Feb 14, 2011 at 14:34 UTC
    There are a couple of ways in which that could break.
    It will break on lines where the first "wap" is not wap1 (we don't know if that can occur in the file) and it will break on wap11 through wap19, which seem to be valid data (OP: the rest can be abbreviated to 2,3,4,5,12,34).
    I seem to remember some regex element that tells perl to do a replacement on the nth occurrence(s) only, which could be used here, but I can't think of it now. Maybe I just made it up.