Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Code Cleanup challenge!

by monktim (Friar)
on Aug 11, 2003 at 13:49 UTC ( [id://282874]=note: print w/replies, xml ) Need Help??


in reply to Code Cleanup challenge!

Here's another suggestion. You can use Getopt and POD (plain ond documentation). All of your command line options are stored in a single hash for easy lookup.
use strict; use warnings; use Getopt::Long; use Pod::Usage; # Process and validate the command line options in @ARGV. my %options; my $parse = new Getopt::Long::Parser; if (!($parse->getoptions('infile=s', \($options{infile}), 'outfile=s', \($options{outfile}), 'help', \($options{help})))) { help(); } if (not defined($options{infile})) { help(); } sub help { pod2usage(0); } __END__ =head1 NAME A.pl - Creates A file =head1 SYNOPSIS A.pl [options] Options: --infile=[file] --help =over 3 =item B<--infile -i=[file]> A file that is used for input, wildcards are allowed =item B<--outfile -o=[file]> Optional parameter for the output file =item B<--help -h -?> Print a brief help message and exits. =head1 DESCRIPTION B<This program> creates a A files. =cut

Replies are listed 'Best First'.
Re: Code Cleanup challenge!
by kesterkester (Hermit) on Aug 12, 2003 at 17:33 UTC
    As long as the options are all being stored in one hash anyhow, I think the reference-to-options-hash usage of Getopts::Long is easier to read:
    [snip] # Process and validate the command line options in @ARGV. my %options; GetOptions ( \%options, qw{ infile=s outfile=s help } ) or help(); [snip]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found