Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994924]
[Lady_Aleena]: atcroft, I"m trying to think of a module I've used that linked to another module.
[Lady_Aleena]: atcroft, I just put a link to another module in one of my local ones. For a normal link L<text|url> the text would be written out then the url would follow the text in brackets <>. However, when I linked to another module, the text was written ..
[Lady_Aleena]: ... but no link. L<module name> might localize to where ever it is, like PerlMonks [id://1026423] does. (Cookies)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2017-05-27 04:16 GMT
Find Nodes?
    Voting Booth?