Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Composing or chaining subroutines

by awwaiid (Friar)
on Jan 17, 2006 at 23:42 UTC ( #523860=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://523860]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-09-17 20:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?