I want to enforce that a script returns usage information if a required option is not passed.But when I call my script without any arguments, it still prints the SQL string instead of dieing with usage information.
use Getopt::Long; use Pod::Usage; #use SQL::Generator; GetOptions ( 'table=s' => \$table, 'id_field=s' => \$email_field, 'state_field=s' => \$state_field, 'zip_field=s' => \$zip_field, 'dob_field=s' => \$dob_field, 'help|?' => \$help, man => \$man ) or die pod2usage(2) ; pod2usage(1) if $help; pod2usage(-exitstatus => 0, -verbose => 2) if $man; print <<EOSQL SELECT $id_field, $email_field, $state_field, $zip_field, $dob_field FROM $table WHERE $zip_field like '336%' or $zip_field like '335%' or $zip_field like '346%' or $zip_field like '337%' or $zip_field like '342%' EOSQL
[tbone@MDB 202025-007]$ perl sql.pl -? Usage: sql.pl [options] sql.pl --table=tabla --id_field=GID --state_field=STATE --dob_fie +ld=DOB Options: --table table --id_field id field --state_field state field --dob_field dob field -help -man [tbone@MDB 202025-007]$ perl sql.pl SELECT , , , , FROM WHERE like '336%' or like '335%' or like '346%' or like '337%' or like '342%' [tbone@MDB 202025-007]$

Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality


In reply to Required options processing Getopt::Long by princepawn

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.