http://qs321.pair.com?node_id=76015


in reply to Line-counts of perl programs/modules

Perhaps I've totally missed the point, but if you want to add line numbers to your program, you could include this snippet in every program you write.
sub lines_count { open IN, "< $0" || die "Can't open file (black magic?)\n"; while( <IN> ) { chomp; printf "%3d: %s\n", $., $_; } close IN; }
So, you could type:

perl my_script.pl -e lines_count > something_that_let_you_print. (Maybe) Useful on system where wc does not exist.

Update Sorry, I've said something wrong. From perlrun...

-e commandline
may be used to enter one line of script. If -e is given, Perl will not look for a script filename in the argument list. Multiple -e commands may be given to build up a multi-line script. Make sure to use semicolons where you would in a normal program.
So what you could write is:

perl -e 'while (<>) {chomp; printf "%3d: %s\n", $., $_; }' < some_script > something_that_let_you_print

Sorry :)