#!usr/bin/perl -w use strict; #File Add2Num.pl my $title = "SOME REPORT TITLE"; my $LINES_PER_PAGE =10; my $ITERATIONS = 100; my $page =1; my $line =9999; if (@ARGV) { print " Usage: add2nums\n". " No command line args allowed\n". " program will prompt for a range of integers\n"; exit(-1); } sub display_range_error { print "ERROR!\n"; print "MUST have 2 positive numbers like: 11 23\n"; } sub page_header { "\n$title , Page $page\n". " ---------------------------------\n". " NUMBER1 || NUMBER2 || ADDITION\n". " ---------------------------------\n"; } while ( (print "Enter a pair of numbers (space between) or quit: "), (my $line =) !~ /^\s*q(uit)?\s*$/i ) { next if $line =~ m/^\s*$/; #re-prompt for blank lines my ($num1, $num2, $kruft) = split(/\s+/,$line); if ( $kruft #user input validation is || ($num1 =~ m/\D/) #important, I like this style || ($num2 =~ m/\D/) #of formatting, others like ) #something different { display_range_error(); next; } foreach (1..$ITERATIONS) { output ($num1, $num2, $num1+$num2); $num1++; $num2++; } } sub output { my ($num1, $num2, $sum) = @_; if ($line++ >= $LINES_PER_PAGE) { if ($page >1) {print "\f"} print page_header; $line = 1; $page++; } printf (" %-9d %-10d %-10d\n", $num1, $num2, $sum); } __END__ C:\TEMP>useprintf.pl Enter a pair of numbers (space between) or quit: 1 2 SOME REPORT TITLE , Page 1 --------------------------------- NUMBER1 || NUMBER2 || ADDITION --------------------------------- 1 2 3 2 3 5 3 4 7 4 5 9 5 6 11 6 7 13 7 8 15 8 9 17 9 10 19 10 11 21 \f SOME REPORT TITLE , Page 2 --------------------------------- NUMBER1 || NUMBER2 || ADDITION --------------------------------- 11 12 23 12 13 25 13 14 27 14 15 29 15 16 31 16 17 33 17 18 35 18 19 37 19 20 39 20 21 41 \f SOME REPORT TITLE , Page 3