Try this: (Monks, please tell me if I am wrong assuming this would work) UnTested...
use vars qw/$reg_u_tbl $dbh $sth $rows $_autoField $_referField /; $reg_u_tbl = "registered_users"; $_referField = "referrer_id"; $_autoField = "MemberId"; $_rankField = "ranked1"; $sth = $dbh->prepare("select * from `$reg_u_tbl` where ##RequirementsH +ere##"); $sth->execute; while($rows = $sth->fetchrow_hashref()) { my $thisMembersid = $rows->{$_autoField}; my $referrersid = $rows->{$_referField}; my $rankName = $rows->{$_rankField}; my $startinglevel = 0; &buildTradRank ($thisMembersid,$referrersid,$rankName,$startinglevel +); } $sth->finish(); sub buildTradRank { ($_rankedid,$_startingid,$_rank,$_level) = @_; my $_fieldName = $_rank . '_traditional'; $_level++; $_countLevels++; $_highLevel = $_level if $_level > $_highLevel; if($_level == 1) { my $_addToSearch = ""; } else { my $_addToSearch = qq~ and `$_rank` = "0"~; } $sth2 = $dbh->prepare(qq{select * from `$reg_u_tbl` where `$_refer +Field` = ?$_addToSearch}); $sth2->execute($_startingid); while(my $_nregu = $sth2->fetchrow_hashref()) { if(!$_nregu->{$_fieldName} || ($_nregu->{$_fieldName} && $_nre +gu->{$_fieldName} != $_rankedid)) { my $_updated = $dbh->do(qq{update `$reg_u_tbl` set `$_fiel +dName` = ? where `$_autoField` = ?}, undef, $_rankedid, $_nregu->{$_a +utoField}); if($_updated) { $_countAllNewlyAdded++; } else { $_countAllNewlyAddedFailures++; $_dbi_errors .= $DBI::errstr . "\n" if $DBI::errstr; } } if(!$_nregu->{$_rank}) { my $_countReferred = $dbh->selectrow_array(qq{select count +(*) from `$reg_u_tbl` where `$_referField` = ? and `$_rank` = "0"}, u +ndef, $_nregu->{MemberId}); if(!$_countReferred) { next; } # Send back to this routine when it returns it should cont +inue with the current data, starting it over SHOULD fork a new routin +e... &buildTradRank($_rankedid,$_nregu->{$_autoField},$_rank,$_ +level); } next; } return 1;#Return when finished... }
By creating one subroutine, you should be able to call it in the middle of it, which should start a new process, with new data and when it returns, then it should continue where it left off... You had it just about right, I only seen an error in your subroutine, you did not add the call to catch the data you passed to the subroutine...

Monks, am I correct in this?

Lee

In reply to Re^3: Recursive programming question by Anonymous Monk
in thread Recursive programming question by ukndoit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.