Options Parsing
Source.
use Getopt::Long qw(:config no_ignore_case); # for GetOptions
use Pod::Usage; # for pod2usage
my $bOptionHelp; # for Option Help {boolean}
my $bOptionMan; # for Option Man {boolean}
my @aOptionFilePath; # for Option File path list {array}
my $sOptionDirPath; # for Option Directory path {string}
my $bOptionSubDir; # for Option Sub directory tracing {boolean}
fnProcess();
sub fnProcess
{
#
### Example: fnProcess()
### http://open-source.tistory.com
### by fckorea.
### Code written by fckorea. [2013-02-03]
#
$bOptionHelp = 1 if($#ARGV == -1);
return if(!fnOptionsParser());
if(@aOptionFilePath)
{
# Processing to using File path list
print "This is my file path list\n";
print "$_\n" foreach(@aOptionFilePath);
}
if($sOptionDirPath ne undef)
{
# Processing to using Directory path
print "This is my directory path\n";
print "$sOptionDirPath";
print " with sub directory" if $bOptionSubDir;
print "\n";
}
}
###============================== Option parsing functions ==============================###
sub fnOptionsParser ### (void) return ValidateOption[bool]
{
#
### Example: fnOptionsParser()
### http://open-source.tistory.com
### by fckorea.
### Code written by fckorea. [2013-02-03]
#
GetOptions(
"help|h|?" => \$bOptionHelp, # Help
"man|m" => \$bOptionMan, # Man
"file|f=s{1,}" => \@aOptionFilePath, # Log file path
"dir|d=s" => \$sOptionDirPath, # Log directory path
"sub|s" => \$bOptionSubDir # Sub directory tracing
) or pod2usage(1);
pod2usage(1) if $bOptionHelp;
pod2usage(-verbose => 2) if $bOptionMan;
return 1;
}
__END__
=head1 NAME
{PROGRAMNAME} - {PROGRAMTITLE} - by fckorea.
=head1 SYNOPSIS
{PROGRAMNAME} [options]
{OPTIONS}
ex.) {PROGRAMNAME} -f "test.txt"
{PROGRAMNAME} -f "test.txt" "test2.txt"
{OPTIONS}
ex.)
Directory
{PROGRAMNAME} -d "test"
SubDirectory
{PROGRAMNAME} -s -d "test"
=head1 OPTIONS
=over 8
=item B<-h, help>
Print a brief help message and exits.
=item B<-m, man>
Prints the manual page and exits.
=item B<-d, Directory>
{OPTION DESCRIPTION}
=item B<-f, File>
{OPTION DESCRIPTION}
=item B<-s, sub>
{OPTION DESCRIPTION}
=back
=head1 DESCRIPTION
B {PROGRAM DESCRIPTION}
=cut
'Perl' 카테고리의 다른 글
[ Perl::Package ] Logger (0) | 2013.03.26 |
---|---|
[ Perl ] Data Types (0) | 2013.02.17 |
[ Perl::Function ] fnGetDirFileList (0) | 2013.02.08 |