Hi All, I would like to pass hash: %{$routes{"ROUTE-252"}} instead of %routes but got this error:
[budi@dev bin]$ ./print_path.pl Type of arg 1 to each must be hash (not hash element) at ./print_path.plline 38, near "}) " Execution of ./print_path.pl aborted due to compilation errors. ---- #use strict; use Graph::Directed; use Data::Dumper; my %routes = ( "ROUTE-252" => { # src => dest CX77 => "ABEP", ABEP => 441, 441 => 427, 427 => 444, 444 => "MGWQ", MGWQ => "CDEF" }, "ROUTE-432" => { AAA => "BBB", BBB => "CCC", CCC => "DDD", DDD => "EEE", EEE => "FFF", XXX => "YYY", YYY => "ZZZ", } ); my $id = "ROUTE-252"; print Dumper $routes{$id}; print_path($id, \%{$routes{$id}}); sub print_path { my ($label, $edges) = @_; my $graph = Graph::Directed->new; while (my ($start, $end) = each $edges{$label}) { #while (my ($start, $end) = each %{$routes{$label}}) { $graph->add_edge($start, $end); } my @sinks = $graph->sink_vertices; for my $source ($graph->source_vertices) { for my $sink (grep $graph->is_sink_vertex($_), $graph->all_successors($source)) { print "$label: ", join ' - ', $graph->path_vertices($source, $sink); print "\n"; } } }