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

Re: Dynamic function chains?

by broquaint (Abbot)
on Sep 15, 2004 at 12:48 UTC ( [id://391148]=note: print w/replies, xml ) Need Help??


in reply to Dynamic function chains?

Just put the functions in a package and call them dynamically e.g
{ package My::Maths; sub power { return exp( $_[0] ) } sub log2 { return log( $_[0] )/log(2.0) } sub loge { return log( $_[0] ) } sub log10 { return log( $_[0] )/log(10.0) } sub round { my $n = shift; return int($n + 0.5) if ($n >= 0); return int($n - 0.5); } sub trunc { return int($_[0]) } sub f1 { return sprintf "%.1f", $_[0] } sub f2 { return sprintf "%.2f", $_[0] } sub f3 { return sprintf "%.3f", $_[0] } sub f4 { return sprintf "%.4f", $_[0] } sub f5 { return sprintf "%.5f", $_[0] } } my $name = shift or die "Usage: $0 FUNC\n"; die "$0: unknown function method\n" unless my $func = My::Maths->can($method); while (<STDIN> ) { chomp; my @in = split; print shift(@in), " "; print join(" ", map &$func($_), @in), "\n"; }
HTH

_________
broquaint

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 04:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found