Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Monks,
I am trying to edit a CSV string, where my goal is to insert a character (a zero) between any occurrence of two consecutive commas. In other words, I'm replacing any missing values with a zero, e.g., 1,2,,4 -> 1,2,0,4The regex I have written does not work as I expected, so I have two questions: 1) What regex would accomplish this, and 2) What is wrong with my approach. There's some subtlety of regexs that I need to familiarize myself with! This code: $s="1,2,3,,5,6,,,9,10,,,,14,15,,,,,,,,,,,,,"; $s=~s/,,/,0,/g; print "$s\n"; '...results in : 1,2,3,0,5,6,0,,9,10,0,,0,14,15,0,,0,,0,,0,,0,,0,,Thanks for considering this issue!
{}think; #Think outside of the brackets
In reply to Regex to replace consecutive tokens by {}think
|
|