in reply to Transform Sequence Problem
Using an array of code references and closures:
use strict; use warnings; sub fgenerator { # some code references my @f = ( sub {map {$_ + 1} @_}, sub {map {log($_)} @_}, sub {map {$_ * 3} @_}, ); my @idx = @_; return sub { @_ = $f[$_]->(@_) for @idx; return @_; }; } # create transform based on indices of function # read: first apply f0, then f1, then f2 my $trans1 = fgenerator( 0, 1, 2 ); my $trans2 = fgenerator( 0, 0, 0 ); # some data my @data = (1, 2, 3); # call the transforms my @trans = $trans1->( @data ); print "@trans\n"; @trans = $trans2->( @data ); print "@trans\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Transform Sequence Problem
by hdb (Monsignor) on Jun 19, 2013 at 14:45 UTC | |
by hdb (Monsignor) on Jun 22, 2013 at 16:55 UTC |
In Section
Seekers of Perl Wisdom