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 - Comment your code thoroughly.. this took me a little longer to code
anything when I started but now it is part of my process of getting anything done.. When I say thoroughly
I mean at the start of you program a detailed description of what it does and what its inputs are and what it outputs.
Also I find it helpfull to end with different error levels which I can check when my util has completed.. and you guessed it, I
document these also.Then, for each subroutine I do a similar thing.. inputs, outputs and what is returned.
Secondly - I build a html page with my utils in a table.. something like - Utilname | Description and commandline args etc | I started this type of thing ages ago and now all I have to do is keep adding to it..
Thirdly - If my util takes command line args I also include a usage subroutine that gets launched when I have not included any args. 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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|