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


in reply to Searching for perl utilities manager

I have found myself in the same situation. Often rather frustrating.. "I know I had a little tool to do this or but what was the syntax..?" etc. etc. The following are some simple tips that have helped me.

I got some advise about this type of thing and since I have started to religiously do it I have not had this problem.

Firstly -

Secondly - Thirdly -

So by way of a silly example my code would look something like -

#! /usr/bin/perl #################################################################### ## ## Name.pl ## ## Name.pl <yourname> ## ## 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 = <STDIN>); 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 <yourname> EOT }

-----
Of all the things I've lost in my life, its my mind I miss the most.