sid_com
sid_com

Reputation: 25117

Which Perl module can format a number with a variable number of leading zeros?

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

Upvotes: 0

Views: 226

Answers (1)

ysth
ysth

Reputation: 98398

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 );

Upvotes: 13

Related Questions