a simple example:
#!/usr/bin/perl use strict; use Getopt::Long; # setup my defaults my $name = 'Bob'; my $age = 26; my $employed = 0; my $help = 0; GetOptions( 'name=s' => \$name, 'age=i' => \$age, 'employed!' => \$employed, 'help!' => \$help, ) or die "Incorrect usage!\n"; if( $help ) { print "Common on, it's really not that hard.\n"; } else { print "My name is $name.\n"; print "I am $age years old.\n"; print "I am currently " . ($employed ? '' : 'un') . "employed.\n"; }
as a programmer from C and Java i have this view that every API has several functions/methods in it. but inside this module i have found only one function. can any one explain what a module is and why does it only contain one function.
Just because Getopt::Long only has one major function doesn't mean it's not worthy of being it's own module. There are plenty of features of that one function (GetOptions) that give it plenty to document. I don't see this as a C/Java vs Perl thing, just the desire to keep it simple, small, useful and resuable.


In reply to Re: Examples for using Getopt::Long by mpeters
in thread Examples for using Getopt::Long by bahadur

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.