Concatenation is for strings. You need to make a copy of the first coderef and make a new coderef that calls the copy. Note that the copy stays around, even though it's gone out of scope, because the new one creates a closure around it. Here's an example:
my $code = sub { print "Sub 1"; }; $code = do { my $oldcode = $code; sub { $oldcode->(); print "Sub 2"; }; }; $code->();
Update: this do block could be further generalized into a subroutine, but that's an exercise left to the reader. :-)
Update: phaylon's solution is much simpler, and the OP seems happy with it, but the closure technique I've shown is a way to get both [or as many as necessary] to execute from a single starting point, [update] and without a loop at all :-P
In reply to Re: subroutine concatenation
by revdiablo
in thread subroutine concatenation
by imcsk8
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |