in reply to interleave two arrays

Try your code with a pair of very large lists. You will quickly find that it is quadratic in both memory and space requirements.

If you think about how much data is passed between subroutines you should be able to see why...

Replies are listed 'Best First'.
Re: Re (tilly) 1: interleave two arrays
by eg (Friar) on Feb 03, 2001 at 09:23 UTC

    Yes, I realize that. This came out of my toying with functional programming in perl. Most of the other solutions I've seen here have side effects that I was trying (for intellectual, rather than practical reasons) to avoid.

      Well a random tip then. Perl does particularly poorly when faced with deep recursion. However it certainly supports functional techniques, and I refer to several examples on my home node.

      BTW I already gave a solution to a generalization of the original problem which is O(n) and has no side-effects at Re (tilly) 1: interleaving lists.