http://www.perlmonks.org?node_id=523860


in reply to Composing or chaining subroutines

Based on other responses I may be missing the point... but how about:
sub chain { my (@subs) = @_; sub { my (@p) = @_; foreach (@subs) { @p = $_->(@p); } } } sub a { $_[0] += 1; print "a - $_[0]\n"; @_ } sub b { $_[0] += 2; print "b - $_[0]\n"; @_ } sub c { $_[0] += 3; print "c - $_[0]\n"; @_ } $x = chain(\&a, \&b, \&c); $x->(7); # Output: # a - 8 # b - 10 # c - 13