Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Im trying to serach through my database and find who referred who this is what I need. I need @refferal to contain like this
$refferal[0] = "1|2|3|4" #first refferals $refferal[1] = "1|2|3|4|5|6" #second refferals $refferal[2] = "1|2|3" #third refferals
And this is the code I tried it with.
#Get Reffers my @ref; (@reffer) = build_reffers($mem_info[2]); ## Build Refferal List sub build_reffers { $REF = shift; $sth = $dbh->prepare("SELECT username FROM wbwm_members WHERE reffera +l='$REF'"); $sth->execute; while($username = $sth->fetchrow_array) { push(@users, $username); } $users = join(/\|/, @users); push(@ref, $users); foreach $name (@users) { build_reffers($name); } return(@ref); }
Now were it freezes my page is this section
foreach $name (@users) { build_reffers($name); }
I dont get how that is freezing the page. This little script im tring to do is finding the first level refferals, and the second level, and so on. Like a first level would reffer a second so, $reffer[0] reffered a $reffer[1]

edited: Tue Nov 5 04:10:04 2002 by jeffa - s/\[/[/g

Replies are listed 'Best First'.
Re: Refferal List
by djantzen (Priest) on Nov 02, 2002 at 23:05 UTC

    Okay first, s/refferral/referral/g;  : )

    Then, add use strict; and use warnings; at the top of the file. If this is a CGI, you might also add use CGI::Carp('fatalsToBrowser') for more helpful error messages.

    What I think what you're seeing is runaway recursion on build_reffers. Can you do away with the join statement and the subsequent return @ref? After all, you're just calling the subroutine in void context, so that code is just needlessly complicating things.

    Update: Anomo++ for the explanation of why it recurses forever.

      @users is defined because it an implicit global variable. This explains why the program never exits. build_reffers keeps pushing onto the same global array and then recurses. This doesn't ever finish. This demonstrates why it is a good idea to use strict and use warnings. And why using my to delcare variables is a good idea. Not to mention the bad database design of storing join'ed values in a single field.
A reply falls below the community's threshold of quality. You may see it by logging in.