Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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

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 wandering the Monastery: (7)
As of 2016-06-24 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...











    Results (322 votes). Check out past polls.