mkenney has asked for the wisdom of the Perl Monks concerning the following question:
Which worked fine in the past with this HORRIBLE code I wrote long ago:Data In: AAA~BB~CCCCC~DDD~ Data Out: AAA BB CCCCC DDD
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:sub add_line_break { my (@out)=@_; for (@out) { s/~+/\n/; s/~+/\n/; s/~+/\n/; s/~+/\n/; ... } return wantarray ? @out :$out[0]; }
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!!! MarkData In: AAA~BB~CCCCC~DDD~ Data Out: AAA~ BB~ CCCCC~ DDD~
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex replacement help
by kennethk (Abbot) on Mar 29, 2011 at 18:43 UTC | |
by Eliya (Vicar) on Mar 29, 2011 at 19:22 UTC | |
by mkenney (Beadle) on Mar 29, 2011 at 19:09 UTC | |
|
Re: regex replacement help
by lostjimmy (Chaplain) on Mar 29, 2011 at 18:41 UTC | |
by mkenney (Beadle) on Mar 29, 2011 at 19:08 UTC | |
|
Re: regex replacement help
by wind (Priest) on Mar 29, 2011 at 18:51 UTC | |
by mkenney (Beadle) on Mar 29, 2011 at 19:11 UTC | |
|
Re: regex replacement help
by jaimon (Sexton) on Mar 29, 2011 at 19:11 UTC | |
by samarzone (Pilgrim) on Mar 30, 2011 at 07:35 UTC | |
by jaimon (Sexton) on Mar 30, 2011 at 17:06 UTC | |
by samarzone (Pilgrim) on Mar 31, 2011 at 10:36 UTC | |
|
Re: regex replacement help
by Cristoforo (Curate) on Mar 29, 2011 at 19:45 UTC | |
|
Re: regex replacement help
by furry_marmot (Pilgrim) on Mar 29, 2011 at 21:47 UTC | |
by choroba (Cardinal) on Mar 31, 2011 at 11:06 UTC |