#!/usr/bin/perl -w # catnumb # # Program to list a program with line numers # Written by Sam Watson Feb. 2008 use strict; my $ver = "1.0.0.0"; my ($temp); my (@lines); my $num = "yes"; # Do you want numbers my $ten = 0; # Counter for 15 lines at a time my $cnt = 1; # Line number my $file = ""; # Option or file name my $dash = "-" x 15; # 15 dashes sub HELP: { # Subroutine to print the help menu print "\nProgram name: catnumb\t version: $ver\n"; print "Usage: catnumb [-hntv] [filename]\n\n"; print "Description: This program will generate a listing of another file on the\n"; print " standard output. Default will generate a listing with line\n"; print " numbers. If no file name is specified it will prompt for the\n"; print " file name to be listed.\n"; print "Options:\n"; print "-h Help menu (this menu)\n"; print "-n Do not print numbers\n"; print "-t Print only 15 lines at a time\n"; print "-v Print the version number\n"; print "\n\n"; } sub GNAME: { print "What file do you want to list? "; $file=; chomp $file; } # What to do if there is an ARGV after the command if ($#ARGV >= 0) { $file=$ARGV[0]; # Get the ARGV if ($file =~ /\A-/) { # Check for option if ($file =~ /h/) { # Check for help HELP; # Execute the help subroutine exit (0); } if ($file =~ /v/) { # Check for print version print "\n\nVersion: $ver\n\n"; exit (0); } if ($file =~ /t/) { # Check for fifteen lines at a time $ten = 1; # Set for ten lines at a time } if ($file =~ /n/) { # Check for no numbers $num = "no"; } $file=""; if ($#ARGV == 0) { # Does it also have a file name specified GNAME; } else { $file = $ARGV[1]; } } } # If no file was specified if ($file eq "") { # Get the file name if no ARGV was supplied GNAME; } open (F, $file) || die "Error in opening $file: $!"; # Open the file or provide the error code @lines=; # Get the lines close (F); print "Listing for $file\n$dash\n"; foreach (@lines) { # List the lines if ($num eq "yes") { # With line numbers printf ("%4d |%s", ($cnt, $_)); } else { # Without line numbers print $_; } $cnt++; if ($ten) { # If set for fifteen lines at a time $temp = ($cnt-1) % 15; if (!$temp) { print "\nPRESS ENTER TO CONTINUE\t\t \"q\" to quit\t"; $temp = ; chomp $temp; print "\n"; if ($temp eq "q") { exit (0); } } } } $cnt--; print "$dash\nListing of $file done.\t$cnt total lines.\n\n";