I have this script that I am working on where I need to accept a number of supplier numbers (1 or more). Is there a way to use the getopts so that I don't have to type -supplier in front of each one of them? If I have 10 suppliers, this gets to be quite cumbersome.
#!/usr/bin/perl
use strict;
use Getopt::Long;
my ($dealer, @supplier, $altsupplier, $min);
GetOptions("dealer=s" => \$dealer,
"supplier:s" => \@supplier,
"altsupplier:s" => \$altsupplier,
"min=s" => \$min) or usage();
print "\n";
print "You have entered:\n\n";
print "Dealer = $dealer\n";
print "Supplier = @supplier\n" if @supplier;
print "Alt Supplier = $altsupplier\n" if $altsupplier;
print "Min = $min\n";
#
# Message about this program and how to use it
#
sub usage()
{
print STDERR << "EOF";
usage: $0 [-dealer -supplier -altsupplier -min]
-h : this (help) message
-dealer : dealer to run for
-supplier : supplier code
-altsupplier : alternate supplier code
-min : minimum name
example: $0 -dealer A875 -supplier CM CX -min TEST123
EOF
exit;
}
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.