in reply to More on Processing Command Line Arguments

And a quick cleanup:

#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use Pod::Usage; #******************************************************** #** Process command line arguments. #******************************************************** GetOptions( 'add=s' =>\my $Add_Record, 'edit=s' =>\my $Edit_Record, 'list=s' =>\my $List_Records, 'view=s' =>\my $View_Record, 'man' => sub {pod2usage({-verbose => 2, -input => \*DATA})}, 'help|?' => sub {pod2usage({-verbose => 1, -input => \*DATA})}, ); if (($Add_Record xor $Edit_Record) xor ($List_Records xor $View_Record +)) { # Run Program } else { # Print manual } __END__ =head1 NAME somescript -- A utility for ... =head1 SYNOPSIS B<somescript --help> for more information somescript [options] Options:

Note a few things.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Re: More on Processing Command Line Arguments
by Ninthwave (Chaplain) on Oct 31, 2003 at 17:01 UTC

    Thank you it is much cleaner but I still can't get that if statement to work. I will get it just need to sketch it out right.

      You know, I saw your script and immediately thought about cleaning it up. I didn't even think about reading your question :)

      A simple way of ensuring that only one option is used at a time:

      GetOptions( 'add=s' =>\my $add, 'edit=s' =>\my $edit, 'list=s' =>\my $list, 'view=s' =>\my $view, 'man' => sub {pod2usage({-verbose => 2, -input => \*DATA}); exi +t}, 'help|?' => sub {pod2usage({-verbose => 1, -input => \*DATA}); exi +t}, ); if (1 == grep { defined } ( $add, $edit, $list, $view )) { print "Good!"; } else { print "Bad!\n"; }

      Cheers,
      Ovid

      New address of my CGI Course.