Perl - Part 7

[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]

Program Line Types

All lines in a Perl program are either:
  1. Blank lines, for appearance.
  2. Comment lines - for our benefit - giving an internal explanation of the program functions, Author etc. These lines start with a # and a space.
  3. Program or Directive lines. The most common (or only) directive line is #!/usr/bin/perl at the very start of each file. Normal program lines are written in Perl.
    • Program lines should be indented, again for appearance. Indent consistently by one or by two spaces.
    • This tidy appearance can pay major dividends in a larger program when you're fault finding.
    • When you start to add program-flow control instructions you'll indent further again, but by the same number of spaces that you've already chosen.
These guidlines about program line types are generally true for all programming languages.

Task 003

This task again comes with a specification, as well as sample (but completely unnacceptably unfriendly) output. Specification:
  1. Create a file called multy01.pl
  2. This program should first display your name and one clear blank line before commencing proper.
  3. The program should prompt the user to enter 3 numbers
  4. The program should then request and accept each number in turn
  5. Once all three numbers have been accepted the program should calculate the product (multiply!) the three numbers
  6. The product should be displayed with suitable explanatory text
  7. One clear line should be displayed at the program end before the command prompt appears
  8. Internally the program should have comment lines to indicate Author, Date, Task & Purpose. These comments should not prevent the line #!/usr/bin/perl from being the very first line in the program as this would most likely cause errors.
Sample output without any explanatory text - which you must provide is shown here:
Hint: Don't re-invent the wheel! This is a sample comment section for the head of a program:
#
# ----------------------------------------------------------------------------------
# Author:	Fachtna Roe	Date:		20061206
# Title:	multy01.pl	Purpose:	To prompt for and
#						to accept three numbers, then to output
#						the product of the numbers.
# ----------------------------------------------------------------------------------
#
Further challenges lie ahead......

[home] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]

Last updated: 20131015-16:45