Hello
archana12
as
Athanaisius told you,
Getopt::Long is the best way to receive arguments for a Perl program. I want just add some words about your specific case. In fact, when you do the effort to use
Getopt::Long to parse args, is worth to add at least a
--help switch. Not only your program will be nicer with users but you can print the help or synopsis when parsing arguments fails instead of having a lonely (for example)
Unknown option: g.
Perl tends to become very idiomatic and here is my common idiom to parse args:
unless ( GetOptions (
"example=s" => \$par_example, # string needed
# more options a
+nd switches..
"help" => \$par_help, # switch
)) { my_show_help(); die "Error in command lin
+e arguments: $!"}
if (defined $par_help){my_show_help();exit;}
Even more: you can profit of the synergy of combining
Getopt::Long with
Pod::Usage if (and you should) you embed
POD documentation into your program. See the very good node
The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!.
So the idiom can be expanded to include a
pod2usage call if
--manual is given.
In your specific case, i.e. a Tk application, your program can also be called by a double click or a custom link with wrong parameters and in this case you'll have no time to read errors emitted by your wise error check. You can circumvent this with a simple
wait_for_input sub and the result will be something like:
unless ( GetOptions (
"example=s" => \$par_example, # string needed
# more options a
+nd switches..
"help" => \$par_help, # switch
)) {pod2usage(-verbose => 1,-exitval => 'NOEXI
+T'); &wait_for_input; exit 1;}
if (defined $par_help){pod2usage(-verbose => 1,-exitval => 'NOEXIT');
+&wait_for_input; exit 0;}
sub wait_for_input{
print "\n\nPress return when ready...\n";
while (<STDIN>){last if $_ }
}
HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.