Your function outputs don't quite match your expected results, but I left them for you to sort out (apart from round which was a bit verbose :).

#! perl -lw use strict; my %funcs = ( power => sub { return exp( $_[0] ) }, log2 => sub { return log( $_[0] )/log(2.0) }, loge => sub { return log( $_[0] ) }, log10 => sub { return log( $_[0] )/log(10.0) }, round => sub { return int( $_[0] + $_[ 0 ] < 0 ? -0.5 : 0.5 ) }, trunc => sub { return int($_[0]) }, f1 => sub { return sprintf "%.1f", $_[0] }, f2 => sub { return sprintf "%.2f", $_[0] }, f3 => sub { return sprintf "%.3f", $_[0] }, f4 => sub { return sprintf "%.4f", $_[0] }, f5 => sub { return sprintf "%.5f", $_[0] }, ); my @ops = map{ m[^[-+](.*)] && exists $funcs{ $1 } ? $funcs{ $1 } : () } @ARGV; undef @ARGV; while (<> ) { chop; my( $row, @in ) = split; print "$row ", join " ", map{ my $val = $_; $val = $_->( $val ) for @ops; $val; } @in; } __END__ P:\test>perl 391141.pl -power 1 0 0 0 1 1 1 2 2 1 1 1 1 2.71828182845905 2.71828182845905 2.71828182845905 7.389056098 +93065 7.38905609893065 2 1 2 0 1 0 0 0 1 2 2.71828182845905 7.38905609893065 1 2.71828182845905 1 1 1 2.7182818 +2845905 3 2 3 4 5 6 0 1 2 3 7.38905609893065 20.0855369231877 54.5981500331442 148.413159102577 +403.428793492735 1 2.71828182845905 7.38905609893065 ^Z P:\test>perl 391141.pl -power -trunc 1 0 0 0 1 1 1 2 2 1 1 1 1 2 2 2 7 7 2 1 2 0 1 0 0 0 1 2 2 7 1 2 1 1 1 2 3 2 3 4 5 6 0 1 2 3 7 20 54 148 403 1 2 7 ^Z

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

In reply to Re: Dynamic function chains? by BrowserUk
in thread Dynamic function chains? by keymon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.