Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Drawing A Dichotomous Key

by tybalt89 (Monsignor)
on May 25, 2020 at 21:49 UTC ( [id://11117249]=note: print w/replies, xml ) Need Help??


in reply to Drawing A Dichotomous Key

Here's something I did for https://www.rosettacode.org/wiki/Display_an_outline_as_a_nested_table#Perl It's not exactly what I think you want, but it may be close.

#!/usr/bin/perl # http://www.rosettacode.org/wiki/Display_an_outline_as_a_nested_table use strict; use warnings; my @rows; my $row = -1; my $width = 0; my $color = 0; our $bg = 'e0ffe0'; parseoutline( do { local $/; <DATA> =~ s/\t/ /gr } ); print "<table border=1 cellspacing=0>\n"; for ( @rows ) { my $start = 0; print " <tr>\n"; for ( @$_ ) # columns { my ($data, $col, $span, $bg) = @$_; print " <td></td>\n" x ( $col - $start ), " <td colspan=$span align=center bgcolor=#$bg> $data </td>\n" +; $start = $col + $span; } print " <td></td>\n" x ( $width - $start ), " </tr>\n"; } print "</table>\n"; sub parseoutline { ++$row; while( $_[0] =~ /^( *)(.*)\n((?:\1 .*\n)*)/gm ) { my ($head, $body, $col) = ($2, $3, $width); $row == 1 and local $bg = qw( ffffe0 ffe0e0 )[ $color ^= 1]; if( length $body ) { parseoutline( $body ) } else { ++$width } push @{ $rows[$row] }, [ $head, $col, $width - $col, $bg ]; } --$row; } __DATA__ insects large wings butterfly small or no wings very long rear legs antenna front mosquito antenna rear grasshopper shorter rear legs horned head rhino beetle not horned head small eyes termite solder large eyes beetle

I used the information from the "Insects" drawing.
When the output is run through links -dump filename it outputs:

+------------------------------------------------------------------ +------+ | insects + | |------------------------------------------------------------------ +------| | large wings | small or no wings + | |-------------+---------------------------------------------------- +------| | butterfly | very long rear legs | shorter rear legs + | |-------------+--------------------------+------------------------- +------| | | antenna | antenna rear | horned | not horned h +ead | | | front | | head | + | |-------------+-----------+--------------+---------+--------------- +------| | | mosquito | grasshopper | rhino | small | l +arge | | | | | beetle | eyes | e +yes | |-------------+-----------+--------------+---------+-----------+--- +------| | | | | | termite | be +etle | | | | | | solder | + | +------------------------------------------------------------------ +------+

Of course, it can also be viewed in a browser.

insects
large wings small or no wings
butterfly very long rear legs shorter rear legs
antenna front antenna rear horned head not horned head
mosquito grasshopper rhino beetle small eyes large eyes
termite solder beetle


Wow, that worked :)

UPDATE: fixed typo in comment

Replies are listed 'Best First'.
Re^2: Drawing A Dichotomous Key
by varanasi (Scribe) on May 27, 2020 at 23:22 UTC

    Wow! This is lovely. Thank you!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117249]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-18 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found