Well, another command-line-parsing-module ... but I must say, I prefer Getopt::Long which is a core module and therefore available everywhere. In addition to that, there are plenty of tests for Getopt::Long, it is more flexible and easier to use (eg. no need to define subs that match the arguments by hand). Apart from that, your module has a couple of problems, eg. it doesn't need Exporter, has a inconsistent interface (why can I say my @singles = $a->getSingles; but not my %keyvals = $a->getKeys), ...

To underline my point, I have rewritten the script given in your POD using Getopt::Long. The only difference is that '-4Adam;Barbara' is now written as two arguments -4 and 'Adam;Barbara'. Btw, your script as given doesn't compile, it uses croak without use Carp; - I have replaced that with a simple warn.

use strict; use warnings; use Getopt::Long; my $usage_msg = <<'EOHELP'; greeter is a sample program for Argdom.pm. --help | -h displays this help message and quits. -o outfile is the file to which the output is written. Can be many, as + in -o f1 -o f2 -o f3. `-' means the STDOUT (default). -xclaim means the output should be exclamatory. -4 X;Y;Z means the greeting should be for X, Y, and Z. Default is ``Wo +rld'' and yourself!. any other args are the greeting. Default is "Hello"./; EOHELP my $xclaim = 0; my $usage = 0; my $greeting = ''; my $forWhom = 'World;to you'; my @outs; GetOptions ("h|help" => \$usage, "xclaim!" => \$xclaim, "4=s" => \$forWhom, "o=s" => \@outs, ) or die $usage_msg; if ($usage) { print $usage_msg; exit; } $greeting .= $_ foreach @ARGV; $greeting = 'Hello' unless $greeting; @outs = qw/-/ unless @outs; my $output = ''; $output .= "$greeting, $_" . ($xclaim ? '!' : '.') . "\n" for (split /;/, $forWhom); foreach my $outfile (@outs) { if ($outfile eq '-') { print $output; } else { open my $outfh, '>', $outfile or warn "Could not open $outfile + for writing: $!"; print $outfh $output; close $outfh; } }

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.


In reply to Re: Argdom.pm by Hofmator
in thread Argdom.pm by revence27

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.