You probably already know this, or perhaps don't need to hear it.
Recursion makes for
biig overheads, and without exception anything
using recursion can be done with loops.
Part of the reason that people use recursion is to map the solution
precisely to the problem set,
this is often due to not understanding the problem, although I'm not implying this is the case here.
i.e Using your simple example.
#!/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: $cou
+nt\n";
}
}
main()
Now this is probably redundant information, or at worst seems like bigotry, but
believe me, I've used recursion in LISP for years, but whilst I enjoyed it, it's not effecient.
If you're just doing this as an exercise in recursion, that's fine, otherwise I'd advocate developing
a loop alternative and benchmarking the two, the dividends should speak for themselves.
--
Brother Frankus.
¤
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.