jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I need to split a string which more or less looks like
Here is my test code
Thnx a lot
LuCa
UPDATE: thnx!! Result: @r = map { s/"//g; $_ }, $inp =~ /("[^"]*"|\S+)/g ;
I need to split a string which more or less looks like
The firt example should split intoAAA * BBB CCC * * "2000 01 00 00 00" "2004 01 00 00 00" or AAA * BBB "CCC DDD" * * "2000 01 00 00 00" *
Note that the first value of the string is ommitted (not important value).* BBB CCC * * 2000 01 00 00 00 2004 01 00 00 00
Here is my test code
Output:#! /usr/bin/perl use strict ; use warnings ; my $inp = 'AAA * BBB CCC * * "2000 01 00 00 00" "2004 01 00 00 00"' ; my @r = $inp =~ /"([^"]*)"|\s+([^\s]*)(?:\s|$)/g ; local $" = "\n"; print "@r";
Not exactly what I had in mind. Any suggestions about what I'm doing wrong here ?Use of uninitialized value in join or string at ./t9.pl line 13. ...... 6 more lines like this ..... * CCC * 2000 01 00 00 00 "2004 00 00"
Thnx a lot
LuCa
UPDATE: thnx!! Result: @r = map { s/"//g; $_ }, $inp =~ /("[^"]*"|\S+)/g ;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: split string using regex
by duff (Parson) on Nov 08, 2007 at 14:51 UTC | |
Re: split string using regex
by grep (Monsignor) on Nov 08, 2007 at 15:01 UTC | |
Re: split string using regex
by gamache (Friar) on Nov 08, 2007 at 15:13 UTC | |
Re: split string using regex
by tuxz0r (Pilgrim) on Nov 08, 2007 at 17:24 UTC | |
by Anonymous Monk on Jun 25, 2013 at 06:20 UTC | |
by hdb (Monsignor) on Jun 25, 2013 at 07:03 UTC |
Back to
Seekers of Perl Wisdom