Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:
Hello
possibly this is an easy thing. But I don't get it. So I'm interested in your answers.
Here my string:
my $str = "1. ...... AB_CD 1.1 ...... EF_GH 1.2 .... IJ_KL_MN 2. ............ OPQR";And here what I would like to have:
my $VAR1 = [{'chapter' => 1, 'name' => 'AB_CD'},{'chapter' => 1.1,'nam +e' => 'EF_GH'},{'chapter' => 1.2,'name' => 'IJ_KL_MN'},{'chapter' => +2,'name' => 'OPQR'}];
I tried a lot of things with split. And I often came near to the desired result. But as said before. I didn't get it completely correctly.
Example I tried: split(/\s\.+\s/, $str);
Thanks alot for your help.
Greetings, Dirk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert string to data structure
by Kenosis (Priest) on Sep 21, 2012 at 16:02 UTC | |
by Dirk80 (Pilgrim) on Sep 21, 2012 at 21:15 UTC | |
|
Re: Convert string to data structure
by Limbic~Region (Chancellor) on Sep 21, 2012 at 15:40 UTC | |
|
Re: Convert string to data structure
by Athanasius (Archbishop) on Sep 21, 2012 at 15:52 UTC | |
|
Re: Convert string to data structure (split)
by tye (Sage) on Sep 21, 2012 at 15:56 UTC | |
by Athanasius (Archbishop) on Sep 21, 2012 at 16:03 UTC | |
by tye (Sage) on Sep 21, 2012 at 16:06 UTC | |
|
Re: Convert string to data structure
by johngg (Canon) on Sep 21, 2012 at 16:52 UTC | |
|
Re: Convert string to data structure
by BrowserUk (Patriarch) on Sep 21, 2012 at 18:28 UTC | |
|
Re: Convert string to data structure
by jdporter (Paladin) on Sep 21, 2012 at 18:44 UTC |