in reply to Zero Padding

Ok, Something short and quick
$num = 13; $len = 6; $padnum = 0 x ($len - length($num)) . $num;
Yoda

Replies are listed 'Best First'.
Re: Re: Zero Padding
by dkubb (Deacon) on Feb 04, 2001 at 23:21 UTC

    I posted a similar solution here, but with one difference - the 0 was quoted.

    At first glance, you might think "So what?", but in benchmarks it actually was 25% faster than the unquoted version.

    I assume this is because perl has to do less work to figure out the context of 0 and transform it into a string.