Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re^2: Need help with filling a complicated data structure

by Lady_Aleena (Curate)
on Nov 17, 2013 at 16:48 UTC ( #1063002=note: print w/replies, xml ) Need Help??

in reply to Re: Need help with filling a complicated data structure
in thread Need help with filling a complicated data structure

ig, this looks like a lot of work, but I am not sure how to incorporate it into the story subroutine. Please see Re^2: Need help with filling a complicated data structure for more, because I can't figure out how to incorporate any of these solves sadly. My weekend has been a wash when it comes to anything I write working.

No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
Lady Aleena

Replies are listed 'Best First'.
Re^3: Need help with filling a complicated data structure
by ig (Vicar) on Nov 17, 2013 at 19:32 UTC

    As you iterate over the lines in a section, you recognize the lines which represent list items, but pass each, separately, to sub item, never producing the data structure you described and never calling sub list.

    What you need to do is detect the entire set of lines that represents a list and pass the set to one of the routines that have been suggested, then pass the resulting data structure to your list sub.

    A start might be to redo the loop over lines in a section to facilitate processing groups of lines and then process all the lines of a list together. Maybe something like the following, untested suggestion might work for you.

    for(my $lineno = 0; $lineno < @$section; $lineno++) { my $line = $section->[$lineno]; if($line =~ m/^\[*#]/) { # This line is the start of a list my $start = $lineno; # Where is the end? my $end = $lineno; $end++ while($section->[$end+1] =~ /^[\*#]/); # Get all the lines that are part of the list my @list_lines = @{$section}[$start..$end]; # Put one of the suggested answers to your initial # request into a subroutine and pass it the set of lines # that represents a single list, getting back the data # structure you requested in your original post. my $internal = parse_list(@list_lines); # Extract the list type and contents from the data # structure my ($type, $list) = @$internal; my $opt = '???'; # Where should $opt come from? # And pass these to the list sub to produce the list. list($tab, $type, $list, $opt); # All the lines of the list have been dealt with. Move # the line number (index into @$section) to the end of # the list then carry on to process the rest of the # section. $lineno = $end; } else { # This line is something other than a list line $line = convert_string($section->[$lineno], $line_magic); line($tab, $line), next if $line =~ /^</; line($tab, "<$line>"), next if $line =~ /^[bh]r$/; $doc_magic->{$1}->(), next if $line =~ /^&\s+(.*)/; blockquote($tab, $1), next if $line =~ /^bq\s(.*)/; row($tab + 1, $1, row_line($2)), next if $line =~ /^\|\s(.+)\s +\|\|(.+)$/; heading($tab, $1, $2, { id => idify($2) }), next if $line = +~ /^([1-6])\s+(.*)/; paragraph($tab, $line, { class => 'author' }), next if $line = +~ /^by /; paragraph($tab, $line); } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063002]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-03-21 06:16 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (264 votes). Check out past polls.