#! /usr/bin/perl #################################################################### ## ## Name.pl ## ## Name.pl ## ## Asks for Age and prints both to STDOUT ## ## Returns ## 0 - Successful ## 1 - No Name on the Command Line ## 2 - No Age Entered ## 3 - Error in Say_Hello Subroutine ## #################################################################### use strict; use warnings; my $rc = 0; my $name = $ARGV[0]; if ($name) { print "Please enter your Age:\n"; chomp (my $age = ); if ($age) { unless (&Say_Hello($name, $age)) { print "Error in subroutine\n"; $rc = 2; } } else { print "You did not enter your age.\n"; $rc = 2; } } else { &Usage; $rc = 1; } exit($rc); ##----------------------------------------------------------------- # Say_Hello - Prints output to STDOUT # Receives $name and $age # Returns - 0 = Fail; 1 = Success ##----------------------------------------------------------------- sub Say_Hello { my $rc = 0; my $helloto = shift; my $howold = shift; if (print "Hello $helloto who is $howold\n") { $rc = 1; } return($rc); } ##----------------------------------------------------------------- # Usage - Printed when no command line params are entered. ##----------------------------------------------------------------- sub Usage { my( $Script ) = ( $0 =~ m#([^\\/]+)$# ); my $Line = "-" x length( $Script ); print << "EOT"; $Script $Line Supply your name on the commandline. You will be asked to supply your age. Both will be printed out. Syntax: $0 EOT }