- or download this
print("$line_num $rest\n");
printf("%03d %s\n", $line_num, $rest);
12345678901
- or download this
$ perl -e'my $i=0; while (<>) { print ++$i, " $_" }' file
1 foo
2 bar
3 baz
4 qux
- or download this
1 234
$ perl -e'my $i="000"; while (<>) { print ++$i, " $_" }' file
...
002 bar
003 baz
004 qux
- or download this
$ perl -e'while (<>) { print "$. $_" }' file
1 foo
2 bar
3 baz
4 qux
- or download this
$ perl -e'while (<>) { printf "%03d %s", $., $_ }' file
001 foo
002 bar
003 baz
004 qux