Created
February 3, 2014 22:17
-
-
Save autarch/8793587 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use v5.16; | |
| use Graph::Directed; | |
| my $g = Graph::Directed->new(); | |
| $g->add_edge( A => 'B' ); | |
| $g->add_edge( B => 'D' ); | |
| $g->add_edge( C => 'D' ); | |
| $g->add_edge( D => 'E' ); | |
| $g->add_edge( A => 'E' ); | |
| my @steps; | |
| sub _follow { | |
| my $target = shift; | |
| my @p = $g->predecessors($target) | |
| or return; | |
| unshift @steps, \@p; | |
| _follow($_) for @p; | |
| } | |
| _follow('E'); | |
| use Devel::Dwarn; Dwarn \@steps; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment