Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Transform Sequence Problem

by BillKSmith (Curate)
on Jun 19, 2013 at 12:32 UTC ( #1039772=note: print w/ replies, xml ) Need Help??

in reply to Transform Sequence Problem

I like your solution. You may save some code using a recursion, but it would require more memory and probably be slower. It is a matter of opinion which would be clearer.


Comment on Re: Transform Sequence Problem
Replies are listed 'Best First'.
Re^2: Transform Sequence Problem
by BillKSmith (Curate) on Jun 22, 2013 at 15:32 UTC
    The recursion was harder than I expected (but just as short)!
    use strict; use warnings; my @data = (1, 2, 3); $, = "\n"; print trans1(\@data,2); BEGIN{ my $seq =[ sub {map {$_ + 1} @_}, sub {map {log($_)} @_}, sub {map {$_ * 3} @_}, ]; sub trans1 { my ($x, $n) = @_; return $seq->[ 0]->(@$x) if $n == 0; return $seq->[$n]->( trans1($x, $n-1, $seq) ); } }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2015-11-26 14:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (701 votes), past polls