Next Trivial Utilities 117

print: File conversion

        sub conversion_path {
          # Do BFS on configuration information
          my ($s, $d) = @_;
          return ($s) if $s eq $d;
          my @queue = ($s);
          my %conversions;
          for (keys %CONF) { push @{$conversions{$1}}, $2 
                if /(.*)->(.*)/; }
          my %good_path_to = ($s => []);
          while (@queue) {
            my ($here) = shift @queue;
            for my $next_type (@{$conversions{$here}}) {
              next if exists $good_path_to{$next_type};  # we've been
            here already
              my $p = [@{$good_path_to{$here}}, $here];
              return @$p, $next_type if $next_type eq $d;
              $good_path_to{$next_type} = $p;
              push @queue, $next_type;
            }
          }
          # no path found
          return;
        }


Next Menu Copyright © 2012 M. J. Dominus