Sun751 has asked for the wisdom of the Perl Monks concerning the following question:
And in above code, I want to "-o" to be optional for example if user don't provide "-o(filename)" that means value for $source_file then I want to take default file suppose "source.txt"; Could any one guide me how can that be done?Please. Cheersuse strict; use warnings; use Getopt::Std; my %options; if (scalar @ARGV < 3) {usage()}; sub usage { print STDERR << "EOF"; \nThis program does... usage: $0 [-hcfo] -h : this (help) message -c : config file -o : Fj xcf release file -x : output file EOF exit; } getopts ("hc:f:o:", \%options); usage() if $options{h}; my $source_file= $options{o}; my $dest_file= $options{x}; my $config_file= $options{c};
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: question about getopt
by moritz (Cardinal) on Jun 24, 2009 at 07:08 UTC | |
by Sun751 (Beadle) on Jun 24, 2009 at 07:33 UTC | |
by moritz (Cardinal) on Jun 24, 2009 at 07:41 UTC | |
by BioLion (Curate) on Jun 24, 2009 at 09:03 UTC | |
by toolic (Bishop) on Jun 24, 2009 at 16:27 UTC | |
|
Re: question about getopt
by hifirock (Novice) on Jun 24, 2009 at 09:13 UTC |