Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Subroutine chaining idiom requested

by premchai21 (Curate)
on May 24, 2001 at 06:49 UTC ( #82799=note: print w/ replies, xml ) Need Help??

in reply to Subroutine chaining idiom requested

Hmmm... I've never read that, but to just construct one on my own:

$agenda = [ sub { "Hello" }, sub { scalar reverse shift }, sub { chop +shift } ]; chain($agenda, [ ]); ### BEGIN GOLF MODE ### sub chain($$) { my@x=@{+pop};foreach(@{+shift}){@x=$_->(@x)}@x } ### END GOLF MODE ###

Update: Fixed argument-modification error, thanks to tilly for pointing that out.

Comment on Re: Subroutine chaining idiom requested
Download Code
Replies are listed 'Best First'.
Re (tilly) 2: Subroutine chaining idiom requested
by tilly (Archbishop) on May 24, 2001 at 07:24 UTC
    Did someone say golf?
    sub chain{(*f,*_)=@_;@_=&$_ for@f;@_}
    Of course you probably want strict compliant and it is bad style to modify your arguments in place. In which case it is probably better to make that:
    sub chain{my($f,$a)=@_;$a=[&$_(@$a)]for@$f;@$a}
    which is still reasonable...

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2016-02-13 06:11 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (419 votes), past polls