# Call as path( $workstation, $server ) sub path { my ( $workstation, $server, @start ) = @_; # initial invocation; make the ws the whole of the path if ( !@start ) { return path( $workstation, $server, $workstation ); } my $last_hop = $start[ -1 ]; # found the server; we're done! if ( $last_hop eq $server ) { return @start; } # for every possible next hop, NEXT_HOP: foreach my $next_hop ( get_next_hops( $last_hop ) ) { # if it's already in our path somewhere, skip it. foreach my $previous_hop ( @start ) { next NEXT_HOP if ( $previous_hop eq $next_hop ); } # look for a path with this as the next hop my @out = path( $workstation, $server, @start, $next_hop ); # if a path was found, return it return @out if @out; } # dead end return (); }