in reply to Re: subroutine concatenation
in thread subroutine concatenation

Using an array is the right solution but this works.
my $code = sub {print "Sub 1\n"}; $code = joincoderefs( $code, sub {print "Sub 2\n"}); &$code; sub joincoderefs { my @refs = @_; return sub { $_->() for @refs }; }
outputs:
Sub 1 Sub 2

--

flounder

Replies are listed 'Best First'.
Re^3: subroutine concatenation
by revdiablo (Prior) on Feb 09, 2005 at 23:41 UTC
    Using an array is the right solution

    I agree that an array of coderefs seems to be the best solution, in this case. Especially since the OP has already responded, saying that the array works. But I still think it's useful to show other techniques -- such as you have done -- which may be more appropriate in other situations. Talking about which one is the "right solution" is a different discussion altogether.