Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Searching for perl utilities manager

by AcidHawk (Vicar)
on Aug 22, 2003 at 07:27 UTC ( [id://285704]=note: print w/replies, xml ) Need Help??


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 -

    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 -

    UtilnameDescription 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://285704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found