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

Replies are listed 'Best First'.
Re^2: Composing or chaining subroutines
by dragonchild (Archbishop) on Jan 18, 2006 at 01:24 UTC
    I don't want to call the other functions. I want to create a function that acts as if I was doing what your function does. See my response to jeffa earlier in the thread as to why I want to do this.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?