Skip to content

Instantly share code, notes, and snippets.

@autarch
Created February 3, 2014 22:17
Show Gist options
  • Save autarch/8793587 to your computer and use it in GitHub Desktop.
Save autarch/8793587 to your computer and use it in GitHub Desktop.
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