#!/usr/bin/perl ########################################### # Mike Schilli, 2003 (m@perlmeister.com) ########################################### use warnings; use strict; our $CVSVERSION = '$Revision: 1.3 $'; my @data; while(<>) { push @data, $_; } my $count = @data; $count = length $count; my $inc = 1; for(@data) { printf "%0${count}d %s", $inc++, $_; } __END__ =head1 NAME linenum - prepend a listing with line numbers =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS amazon listing =head1 DESCRIPTION B adds line numbers to an input file, making sure to use a constant width of the line number field. To accomplish this, it goes through the entire input file first, determines the number of lines and then zero-pads accordingly: 1 #!/usr/bin/perl .. 9 __END__ 01 #!/usr/bin/perl .. 99 __END__ 001 #!/usr/bin/perl .. 100 __END__ It prints its output to STDOUT. =head1 LEGALESE Copyright 2004 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR 2004, Mike Schilli