note
frankus
You probably already know this, or perhaps don't need to hear it.<br>
Recursion makes for <i>biig</i> overheads, and without exception anything
using recursion can be done with loops.<p>
Part of the reason that people use recursion is to map the solution
precisely to the problem set,<br>
this is often due to not understanding the problem, although I'm not implying this is the case here.<br>
i.e Using your simple example.
<code>
#!/usr/local/bin/perl -w
use strict;
sub main() {
doSomething(1,2,0);
print "Done\n";
}
sub doSomething{
my ($data1, $data2, $count)=@_;
for($count..3){
$data1++,$data2++,$count++;
print "\$data1: $data1, \$data2: $data2, \$count: $count\n";
}
}
main()
</code>
<br>
Now this is probably redundant information, or at worst seems like bigotry, but<br>
believe me, I've used recursion in LISP for years, but whilst I enjoyed it, it's not effecient.
<p>If you're just doing this as an exercise in recursion, that's fine, otherwise I'd advocate developing<br>
a loop alternative and benchmarking the two, the dividends should speak for themselves.
<p>--<br></br>
<i>Brother <A HREF="/index.pl?node=Frankus&lastnode_id=1072">Frankus</A>.</i>
<p align="center">¤</p>
130071
130071