in reply to [OT: D] Re: sprintf and arrays of unknown (in advance) length
in thread sprintf and arrays of unknown (in advance) length
Why? Perl has thanks to variable interpolation a huge flexibility, that's effectively a built in template language. Plus loads of operators to recombine strings.
What's the point overloading the printf formats with more syntax if we can already have it all in a short, expressive and canonical way?
DB<90> sub format_n { my $n= shift; printf "%b" x $n ." ", splice @_ +, 0, $n while @_ } DB<91> format_n 3,(1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0) 101 100 101 010 DB<92> format_n 4,(1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0) 1011 0010 1010 DB<93> format_n 5,(1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0) 10110 01010 10000
(non-destructive version left as exercise)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
---|