in reply to Re^4: Advise on sql table mapping.
in thread Advise on sql table mapping.

I'm not sure what you mean by "calling @results from outside the loop", but if you mean what I think you mean, you might benefit from Coping With Scoping. @results is not visible anymore once find_joins has finished running. Use the return value(s) of find_joins, like I did.

Replies are listed 'Best First'.
Re^6: Advise on sql table mapping.
by Anonymous Monk on May 19, 2008 at 23:39 UTC

    Actually @results did exist because I had also removed: my @results;

      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.

        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) { ... };