I have a string like this:
*******voltage:156.7;****current:44;****voltage:98;current:0.9;***voltage:45;***
where the * is long-winded junk we don’t care about. What we want to do produce a new string, identical, but to find every “voltage” and replace it with voltage1, voltage2, etc. so each voltage reading has a unique key name. Likewise for current (and several others).
It is not clear what is the slickest way to do this in Perl. It must be readable by modestly skilled Perl programmers and EEs. Ultimate speed is not important, and we’d like to stick with built-in Perl capabilities rather than use some crazy module. None of us modestly skilled guys have found a way to do this without making a nonworking mess of code.
There’s probably a nice way to do this with regexes, but if it’s a complex guru-only regex, never mind!
A second green checkmark if the solution can run on the ancient Perl version 5.6
Output:
*******voltage1:156.7;****current:44;****voltage2:98;current:0.9;***voltage3:45;***