in reply to Got's to be a better way
There's nothing wretchedly wrong with your code that I can see. One this that might make it prettier (and a bit more intuitive) is to park your padding logic in a sub/function similar to the following:
use strict; while (<DATA>) { chomp; print padded($_), "\n"; } sub padded { #left-pads enough zeros to a number to ensure that there are at leas +t #four digits my ($num) = @_; my $padded = '0' x (4 - length($num)); return $padded . $num; } __DATA__ 23 102 2003 9
I am now going to make the obligatory statements about using the -w flag and use strict. There.
|
|---|