Welcome!
Thanks for visiting. If you found this information interesting or useful (or you think I'm dead wrong about something) I'd like to invite you to leave a comment on this post. You can also
subscribe to my RSS feed or sign up for email updates on the right-hand side of the page.
If you Digg what you StumbleUpon, find my writing del.icio.us, or are one of the Technorati, you know what to do:
Using next_successor with Graph::Traversal
I recently needed to do a graph traversal using the excellent perl Graph library, but I needed to determine the order for visiting new nodes in the fringe myself. Graph::Traversal provides a next_successor attribute which takes a code ref so that you can specify this behavior yourself. Unfortunately, in version 0.80 that feature isn’t well documented, and if you try to use it, you get an “unknown attribute” error. I’ve submitted a patch to enable, document, and test the feature. Now, if you want (for example) to do a breadth-first traversal, but visit the nodes in reverse alphabetical order, you can do this:
Graph::Traversal::BFS->new(
first_root => 'a',
pre => sub { print $_[0]; }
next_successor => sub { (reverse sort keys %{$_[1]})[0]; },
)->bfs;
Related posts:
- Custom Firefox search shortcuts I've come across a little trick that isn't complicated at...
- My first CPAN acknowledgement It's a small thing, but I'm listed in the acknowledgements...
- The Value of Community, or Why I Love Perl I've been asked a number of times recently why I...
- Template Toolkit: how to generate static HTML on any path My company generates our website using Template Toolkit's ttree tool....

