in reply to How to implement printf like functions
In Perl, the arguments to subs/functions are sent as lists. So you can put your first element as the format and the subsequent elements are the args you want to send. Here is a dummy function that does something like that
#!/usr/bin/perl -w use strict; my @ret = pow("3 2 3 2",(2,3,5,7)); print +($_,$/) for @ret; sub pow { my ($fmt, @values) = @_; my @fmts = split /\s+/, $fmt; return map {$_**shift(@fmts) } @values; } __END__ 8 9 125 49
The first param's first element tells you by what power the first arg should be raised.
|
|---|