in reply to Composing or chaining subroutines
Is eval to evil for this? ;)
use strict; use warnings; my $chain1 = chain(qw( rev Foo::uc b2_ )); my $chain2 = chain(qw( Foo::uc b2_ rev )); print for $chain1->(qw( foo bar baz )); print for $chain2->(qw( foo bar baz )); sub chain { my $str = '@_'; $str = '&' . "$_($str)" for @_; return sub { eval $str }; } sub rev { map scalar reverse, @_ } sub b2_ { my @a=@_;map {s/b/_/g;$_} @a } package Foo; sub uc { map ucfirst, @_ }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Composing or chaining subroutines
by dragonchild (Archbishop) on Jan 17, 2006 at 17:14 UTC |