blog/content/post/2009/11/04/2009-11-04-00001258.md

3.8 KiB

title author date wordtwit_post_info categories
Getopt::Long と Pod::Usage の使用例 kazu634 2009-11-04
O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4903;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}
Perl

CPANでの説明そのものですけど、貼り付けておきますね。

# === Libraries ===
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
my $man  = ;
my $help = ;
## Parse options and print usage if there is a syntax error,
## or if usage was explicitly requested.
GetOptions( 'help|?' => \$help, man => \$man ) or pod2usage(2);
pod2usage(1) if $help;
pod2usage( -verbose => 2 ) if $man;
## If no arguments were given, then allow STDIN to be used only
## if it's not connected to a terminal (otherwise print usage)
pod2usage("$0: No files given.") if ( ( @ARGV ==  ) && ( -t STDIN ) );
__END__
=head1 NAME
sample - Using GetOpt::Long and Pod::Usage
=head1 SYNOPSIS
sample [options] [file ...]
Options:
-help            brief help message
-man             full documentation
=head1 OPTIONS
=over 8
=item B<-help>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=head1 DESCRIPTION
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=cut