Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Reading an arbitrary hierarchy into a hash tree

by runrig (Abbot)
on Aug 07, 2001 at 03:30 UTC ( #102650=note: print w/replies, xml ) Need Help??


in reply to Reading an arbitrary hierarchy into a hash tree

Just for the fun of it, here's a way which translates your text into XML, then uses XML::Simple on the result:
use strict; use Data::Dumper; use XML::Simple; my $str = do { local $/=undef; <DATA> }; LOOP: { for ($str) { # Make start/end tags for current level s#^(\w+)(.*?)(?=^[\w<]|\Z)#<$1>$2\n</$1>\n#smg; # Process next level s/^\t//mg or last LOOP; } redo LOOP; } my $xs = XML::Simple->new(suppressempty=>''); # Add root element my $href = $xs->XMLin("<root>$str</root>"); print Dumper($href); __DATA__ abc def ghi jkl mno pqr

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://102650]
help
Chatterbox?
[Corion]: :-D
[stevieb]: I suppose I'll have to delete the 2.36 ver, then re-upload 2.36.1 and 2.36.2, and re-version 2.36 as 2.36.0
[Corion]: stevieb: Naah, I wouldn't delete versions from CPAN. Just up the version to 2.37 resp. 2.37.0 / 2.37.1 etc

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2017-01-19 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.