Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Convert string to data structure

by Limbic~Region (Chancellor)
on Sep 21, 2012 at 15:40 UTC ( #994924=note: print w/ replies, xml ) Need Help??


in reply to Convert string to data structure

Dirk80,
Something like this untested code might work:

my @token = split ' ', $str; for my $idx (reverse 0 .. $#token) { my $item = $token[$idx]; $item =~ s/\.+$//; splice(@token, $idx, 1) if ! length($item); } my @structure; for my $idx (grep {$_ % 2} 1 .. $#token) { push @structure, { chapter => $token{$idx - 1}, name => $toekn{$idx} }; }

Cheers - L~R


Comment on Re: Convert string to data structure
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-02 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls