Dear Monks,
I'm currently trying to add functionality to a program, my program is called mkpq and I'd like to add certain options such as mkpq -a <queuename>.
I'm wondering if this is better off run as a custom subroutine or defined in @ARGV, here is what I have so far as in printing the command usage but I do not know how to reference the commands and store them for later use in the program.
$VERSION = 0.01;
$uname = "uname";
# Set ARGS
if (@ARGV < 1) {
die "usage: $0 \n
-a <queuename> -- Add a queue\n
-r <queuename> -- Remove a queue\n
-s <queuename> -- Check queue/spooler status\n
-f <queuename> -- Force option\n
-h print this help file\n";
}
Any help at all would be greatly appreciated!
Update!
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my ($add,$remove,$status,$force);
my %add_opts;
GetOptions ( \%add_opts, 'queue=s', 'label=s' );
sub display_help {
die "Usage:
-a <queuename> -- Add a queue\n
-r <queuename> -- Remove a queue\n
-s <queuename> -- Check queue/spooler status\n
-f <queuename> -- Force option\n
-v Version Information\n
-h print this help file\n";
}
GetOptions ( version => sub{ print "This is mkpq Version 0.01\n"; exit
+; } );
GetOptions ( help => \&display_help );
if ($add_opts {'queue'}) {
print "Test\n";
}
else {
print &display_help;
}
First of all, thanks for all of the help everyone has provided. I do in fact have another question; since this program needs to be a bit intuitive. My initial thought process behind this program would be:
1.) The first switch will determine the course of the program. (mkpq -a or -r) I was going to have if statements for -a or -r, then sub-switches if you will.
Example mkpa -a -q <printername>
(the a switch invokes the system commmand to add a printer -q will hold the string which is the name of the printer.
My question is this: How to I set this up in such a manner? Should I determine if () with subprocess' running under it?
if (a) { # switch to add a queue
do system($somecmd $q); #run system cmd with entered string.
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.