Hello Monks! I've got a problem that I'm sure has a simple solution yet my terrible (read non-existant) grasp of regexes makes a real struggle. I need to split some text that contains a tilda up with a line return.
Example:
Data In:
AAA~BB~CCCCC~DDD~
Data Out:
AAA
BB
CCCCC
DDD
Which worked fine in the past with this HORRIBLE code I wrote long ago:
sub add_line_break
{
my (@out)=@_;
for (@out) {
s/~+/\n/;
s/~+/\n/;
s/~+/\n/;
s/~+/\n/;
...
}
return wantarray ? @out :$out[0];
}
Now I need to do the same thing but leave the tilda on the end. The lines have varying numbers elements in them so I'd love it to do it for everyone of them without me having to duplicate the regex (which I'm sure I only had to do because of my poor grasp.
Example:
Data In:
AAA~BB~CCCCC~DDD~
Data Out:
AAA~
BB~
CCCCC~
DDD~
Can someone help me out. I'm hoping some real world examples will help me grasp regexs finally. I've struggled with them for YEARS. Tried different books and sites and I still can't close the loop for some reason.
Thanks as always for your help!!!
Mark