#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |