tags:

views:

75

answers:

1

Could somebody tell me a Perl module with a function, that converts digits like this:

func( 1, 3 ) # returns 001 
func( 23, 4 ) # returns 0023
func( 7, 2 ) # returns 07
+13  A: 

No module, just sprintf, though with the arguments in the other order and a suitable format argument:

sprintf( '%0*d', 3, 1 );
sprintf( '%0*d', 4, 23 );
sprintf( '%0*d', 2, 7 );
ysth
You actually don't need to reverse the order of the arguments, use the positional modifier ($) in the sprintf: print sprintf( '%0*2$d', 23, 4 ); returns 0023. If you are going to use a double quoted string ("" or qq{}) then you'd need to escape the $.
MkV