eddor1614 has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks.
I'm looking for an elegant solution to an insignificant issue, already resolved :)
I have my data like this:
abc def data 123 ghi jkl "data with spaces" 456
and I need to print something like this:
abc-def-data1 ghi-jkl-data with spaces
so, space delimits fields, but third field can have spaces if it's surrounded by double quotes.
Right now I'm doing this:
print "$1-$2-".($4 || $3) if /(\w+)\s(\w+)\s("([^"]+)"|(\w+))/;
I'm sure there should be a better way. I need $3 to have the third field, without the quotes.
Anyone knows how to do it?
Thanks.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Nested grouping or capturing inside capturing
by ww (Archbishop) on Nov 22, 2011 at 19:47 UTC | |
by eddor1614 (Beadle) on Nov 22, 2011 at 20:01 UTC | |
Re: Nested grouping or capturing inside capturing
by Not_a_Number (Prior) on Nov 22, 2011 at 20:26 UTC | |
Re: Nested grouping or capturing inside capturing
by hbm (Hermit) on Nov 22, 2011 at 20:16 UTC | |
Re: Nested grouping or capturing inside capturing
by remiah (Hermit) on Nov 23, 2011 at 13:40 UTC |
Back to
Seekers of Perl Wisdom