Thank you - that looks extremely promising. I really, really like that it uses a call-back to get the dependancies rather than asking for a complete list of dependancies up front. Since S::T has to loop through everything anyway, why loop through it in the calling code, too, when a callback will implicitly perform the loop?
It does seem to perform the sort in the reverse order of what I wanted, but thankfully perl makes that pretty darned trivial.
For posterity, my example has changed to:
use Sort::Topological;
use strict;
use Data::Dumper;
my %before =
(
a => _s(qw(c)),
b => _s(qw(d e)),
c => _s(qw(l)),
d => _s(qw(e a)),
e => _s(qw(c)),
f => _s(qw(g d)),
g => _s(qw(c)),
h => _s(qw(g i)),
i => _s(qw()),
j => _s(qw(c)),
k => _s(qw()),
l => _s(qw()),
n => _s(qw(c)),
o => _s(qw()),
);
# print Dumper(\%before);
my @order = reverse
Sort::Topological::toposort(
sub {
@{$before{$_[0]}};
},
[ keys %before ],
);
print "@order\n";
sub _s
{
[ @_ ]; #my %h = map { $_ => 1 } @_;
#\%h
}
And the result is:
l c a e i g d o f b h k j n
At this point, this (simple) example is working. Which gives me reasonable confidence since I did manage to create a non-working example in the first place. Again, thanks!
The only issue is that the module drags in too much - too bad it wasn't separated out into its own distribution. Oh well, can't win 'em all!
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.