I was thinkg of another attemt to solve this puzzle.
Making hash notatin text and eval it
And this is nothing better than hdb's one, maybe ...
use strict; use warnings; use Data::Dumper; sub proc{ my($pre, $cnt_cur, $end_brackets)=@_; my $buff; $buff = $pre->{data} ; if ($cnt_cur > $pre->{cnt}){ #next is children $buff .=' => {'; push(@$end_brackets, '}'); }elsif ( $cnt_cur == $pre->{cnt} ){ #next is brothers $buff .= ' => undef ,'; } else { $buff .= ' => undef ,'; for ( 1 .. ($pre->{cnt} - $cnt_cur) ){ #output right bracke +t till that depth $buff .= pop(@$end_brackets) . ","; } } return $buff; } my ($pre, $cnt, $ret, @end_brackets); $ret='{'; while(<DATA>){ $cnt = $_ =~ s/\s{4}//g; $cnt = $cnt || 0; if ( $pre ){ $ret .= proc($pre, $cnt, \@end_brackets); } $pre={cnt => $cnt, data=>$_}; } $ret .= proc($pre, 0, \@end_brackets); $ret .= '}'; print Dumper eval($ret); __DATA__ one two three four three_another four_another five six seven eight nine ten 11 12 13 14 15 16 17 18 19 20 21 22 23 24

In reply to Re: Parse data representing hash by remiah
in thread Parse data representing hash by peterp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.