in reply to sprintf vs. substr (for zero-padded values)
It's just not worth the hassle to patch these bugs when sprintf is already sea-worthy.sub one { my ($number) = @_; my $padded = sprintf("%09d",$number); $padded; } sub two { my ($number) = @_; my $padded = "000000000"; my $length = length($number); substr($padded,(-$length),$length,$number); $padded; } print one(-6),"\n"; # -00000006 print two(-6),"\n"; # 0000000-6 print one(43/6),"\n"; # 000000007 print two(43/6),"\n"; # 7.16666666666667
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: sprintf vs. substr (for zero-padded values)
by Theseus (Pilgrim) on Jul 15, 2002 at 21:15 UTC | |
by tadman (Prior) on Jul 18, 2002 at 12:13 UTC | |
by Theseus (Pilgrim) on Jul 18, 2002 at 13:30 UTC | |
by Abigail-II (Bishop) on Jul 18, 2002 at 13:38 UTC |