Which was dumb btw. This code you wrote is really complex. Apparently reading the llama book is just not cutting it. I can modify your code to make it do what I want it to, but I will not use it until I completely understand it and I have been staring at that sub for hours. The function calling itself is a strange and new concept for me.
What is going on in the for loop?
for my $link (grep { ! $visited->{$_} } @{$links{$start}}) {
Amazing. Thanks again for the brain twisting code.
After all this is over, all that will really have mattered is how we treated each other.
| [reply] [d/l] |
I struggled with the concept of recursion for a long time until I grasped it, myself. The idea is that, to get from A to B, you go one step from A (say, to A1) and then just need to find the way from A1 to B. Now, to get from A1 to B, you take one step from A1 (say, to A2) and then just need to find the way from A2 to B ...
The for loop just filters out all the places we've been before for this path. It can be written as follows:
my @possible_next_steps = @{$links{$start}};
my @unvisited_nodes = grep { ! $visited->{$_} } @possible_next_steps;
# Now, for each unvisited node, see if we can reach the goal from ther
+e
for (@unvisited_nodes) {
...
};
| [reply] [d/l] [select] |