=encoding utf8 =head1 NAME =begin original Getopt::Long - Extended processing of command line options =end original Getopt::Long - コマンド行オプションの拡張処理 (訳注: (TBR)がついている段落は「みんなの自動翻訳@TexTra」による 機械翻訳です。) =head1 SYNOPSIS use Getopt::Long; my $data = "file.dat"; my $length = 24; my $verbose; GetOptions ("length=i" => \$length, # numeric "file=s" => \$data, # string "verbose" => \$verbose) # flag or die("Error in command line arguments\n"); =head1 DESCRIPTION =begin original The Getopt::Long module implements an extended getopt function called GetOptions(). It parses the command line from C<@ARGV>, recognizing and removing specified options and their possible values. =end original Getopt::Longモジュールは、GetOptions()と呼ばれる拡張getopt関数を実装します。 C<@ARGV>からのコマンド行を解析し、指定されたオプションとその可能な値を認識し削除します。 (TBR) =begin original This function adheres to the POSIX syntax for command line options, with GNU extensions. In general, this means that options have long names instead of single letters, and are introduced with a double dash "--". Support for bundling of command line options, as was the case with the more traditional single-letter approach, is provided but not enabled by default. =end original この関数は、コマンドラインオプションのPOSIX構文に準拠し、GNU拡張を使用しています。 一般に、これは、オプションが単一文字ではなく長い名前を持ち、二重ダッシュ「--」で導入されることを意味します。 従来の単一文字による方法と同様に、コマンドラインオプションのバンドル化がサポートされていますが、デフォルトでは使用可能になっていません。 (TBR) =head1 Command Line Options, an Introduction =begin original Command line operated programs traditionally take their arguments from the command line, for example filenames or other information that the program needs to know. Besides arguments, these programs often take command line I as well. Options are not necessary for the program to work, hence the name 'option', but are used to modify its default behaviour. For example, a program could do its job quietly, but with a suitable option it could provide verbose information about what it did. =end original コマンドラインで操作されるプログラムは、伝統的にコマンドラインから引数(例えば、ファイル名やプログラムが知る必要のあるその他の情報)を受け取ります。 引数に加えて、これらのプログラムはしばしばコマンドラインIも受け取ります。 オプションはプログラムが動作するために必要ではないので、「オプション」という名前が付いていますが、デフォルトの動作を変更するために使用されます。 例えば、プログラムはそのジョブを静かに行うことができますが、適切なオプションを使えば、それが何をしたかについての詳細な情報を提供することができます。 (TBR) =begin original Command line options come in several flavours. Historically, they are preceded by a single dash C<->, and consist of a single letter. =end original コマンドラインオプションにはいくつかの種類があります。 歴史的には、これらの前には1つのダッシュC<->が付き、1つの文字で構成されています。 (TBR) -l -a -c =begin original Usually, these single-character options can be bundled: =end original 通常、これらの1文字のオプションは次のようにまとめることができます。 (TBR) -lac =begin original Options can have values, the value is placed after the option character. Sometimes with whitespace in between, sometimes not: =end original オプションは値を持つことができ、値はオプション文字の後に置かれます。 間に空白文字がある場合もあれば、ない場合もあります。 (TBR) -s 24 -s24 =begin original Due to the very cryptic nature of these options, another style was developed that used long names. So instead of a cryptic C<-l> one could use the more descriptive C<--long>. To distinguish between a bundle of single-character options and a long one, two dashes are used to precede the option name. Early implementations of long options used a plus C<+> instead. Also, option values could be specified either like =end original これらのオプションの非常に謎めいた性質のために、長い名前を使用する別のスタイルが開発されました。 したがって、謎めいたC<-l>の代わりに、より記述的なC<--long>を使用できます。 単一文字オプションの束と長いオプションを区別するために、オプション名の前に2つのダッシュを使用します。 長いオプションの初期の実装では、代わりにプラスC<+>を使用していました。 また、オプション値は次のように指定できます。 (TBR) --size=24 =begin original or =end original または (TBR) --size 24 =begin original The C<+> form is now obsolete and strongly deprecated. =end original C<+>形式は廃止され、非推奨になりました。 (TBR) =head1 Getting Started with Getopt::Long =begin original Getopt::Long is the Perl5 successor of C. This was the first Perl module that provided support for handling the new style of command line options, in particular long option names, hence the Perl5 name Getopt::Long. This module also supports single-character options and bundling. =end original Getopt::Longは、CのPerl5の後継です。 これは、新しいスタイルのコマンドラインオプション、特に長いオプション名の処理をサポートした最初のPerlモジュールであり、Perl5ではGetopt::Longという名前になっています。 このモジュールは、単一文字オプションとバンドルもサポートしています。 (TBR) =begin original To use Getopt::Long from a Perl program, you must include the following line in your Perl program: =end original PerlプログラムからGetopt::Longを使用するには、Perlプログラムに次の行を含める必要があります。 (TBR) use Getopt::Long; =begin original This will load the core of the Getopt::Long module and prepare your program for using it. Most of the actual Getopt::Long code is not loaded until you really call one of its functions. =end original これにより、Getopt::Longモジュールのコアがロードされ、それを使用するプログラムが準備されます。 実際のGetopt::Longコードのほとんどは、その関数の1つを実際に呼び出すまでロードされません。 (TBR) =begin original In the default configuration, options names may be abbreviated to uniqueness, case does not matter, and a single dash is sufficient, even for long option names. Also, options may be placed between non-option arguments. See L for more details on how to configure Getopt::Long. =end original デフォルトの構成では、オプション名は一意になるように省略できます。 大文字と小文字は区別されず、長いオプション名の場合でも1つのダッシュで十分です。 また、オプションをオプション以外の引数の間に置くこともできます。 Getopt::Longの構成方法の詳細は、Lを参照してください。 (TBR) =head2 Simple options =begin original The most simple options are the ones that take no values. Their mere presence on the command line enables the option. Popular examples are: =end original 最も単純なオプションは、値を取らないオプションです。 コマンドラインに存在するだけで、オプションが有効になります。 一般的な例は次のとおりです。 (TBR) --all --verbose --quiet --debug =begin original Handling simple options is straightforward: =end original 単純なオプションの処理は簡単です。 (TBR) my $verbose = ''; # option variable with default value (false) my $all = ''; # option variable with default value (false) GetOptions ('verbose' => \$verbose, 'all' => \$all); =begin original The call to GetOptions() parses the command line arguments that are present in C<@ARGV> and sets the option variable to the value C<1> if the option did occur on the command line. Otherwise, the option variable is not touched. Setting the option value to true is often called I the option. =end original GetOptions()への呼出しは、C<@ARGV>にあるコマンドライン引数を解析し、オプションがコマンド行にある場合は、オプション変数を値C<1>に設定します。 そうでない場合は、オプション変数は変更されません。 オプション値を真に設定することは、オプションを有効にすると呼ばれます。 (TBR) =begin original The option name as specified to the GetOptions() function is called the option I. Later we'll see that this specification can contain more than just the option name. The reference to the variable is called the option I. =end original GetOptions()関数に指定されたオプション名は、オプションIと呼ばれます。 後で、この仕様にはオプション名以上のものを含めることができることがわかります。 変数への参照は、オプションIと呼ばれます。 (TBR) =begin original GetOptions() will return a true value if the command line could be processed successfully. Otherwise, it will write error messages using die() and warn(), and return a false result. =end original GetOptions()は、コマンドラインが正常に処理された場合はtrueを返します。 それ以外の場合は、die()およびwarn()を使用してエラーメッセージを書き込み、falseを返します。 (TBR) =head2 A little bit less simple options =begin original Getopt::Long supports two useful variants of simple options: I options and I options. =end original Getopt::Longは、IオプションとIオプションという2つの便利な単純オプションをサポートしています。 (TBR) =begin original A negatable option is specified with an exclamation mark C after the option name: =end original 否定可能なオプションは、オプション名の後に感嘆符Cを付けて指定します。 (TBR) my $verbose = ''; # option variable with default value (false) GetOptions ('verbose!' => \$verbose); =begin original Now, using C<--verbose> on the command line will enable C<$verbose>, as expected. But it is also allowed to use C<--noverbose>, which will disable C<$verbose> by setting its value to C<0>. Using a suitable default value, the program can find out whether C<$verbose> is false by default, or disabled by using C<--noverbose>. =end original 現在、コマンドラインでC<--verbose>を使用すると、期待どおりにC<$verbose>が有効になります。 しかし、C<--noverbose>を使用することもできます。 これは、その値をC<0>に設定することによってC<$verbose>を無効にします。 適切なデフォルト値を使用して、プログラムはC<$verbose>がデフォルトでfalseであるか、C<--noverbose>を使用して無効になっているかを調べることができます。 (TBR) =begin original (If both C<--verbose> and C<--noverbose> are given, whichever is given last takes precedence.) =end original (C<--verbose>とC<--noverbose>の両方が指定されている場合は、最後に指定された方が優先されます)。 (TBR) =begin original An incremental option is specified with a plus C<+> after the option name: =end original インクリメンタルオプションは、オプション名の後にプラス記号C<+>を付けて指定します。 (TBR) my $verbose = ''; # option variable with default value (false) GetOptions ('verbose+' => \$verbose); =begin original Using C<--verbose> on the command line will increment the value of C<$verbose>. This way the program can keep track of how many times the option occurred on the command line. For example, each occurrence of C<--verbose> could increase the verbosity level of the program. =end original コマンドラインでC<--verbose>を使用すると、C<$verbose>の値が増加します。 これにより、プログラムはコマンドラインでオプションが何回発生したかを追跡できます。 たとえば、C<--verbose>が発生するたびに、プログラムの冗長レベルが増加します。 (TBR) =head2 Mixing command line option with other arguments =begin original Usually programs take command line options as well as other arguments, for example, file names. It is good practice to always specify the options first, and the other arguments last. Getopt::Long will, however, allow the options and arguments to be mixed and 'filter out' all the options before passing the rest of the arguments to the program. To stop Getopt::Long from processing further arguments, insert a double dash C<--> on the command line: =end original 通常、プログラムはコマンドラインオプションだけでなく、ファイル名などの他の引数も受け取ります。 常にオプションを最初に指定し、他の引数を最後に指定することをお勧めします。 ただし、Getopt::Longでは、オプションと引数を混在させて、残りの引数をプログラムに渡す前にすべてのオプションを「除外」することができます。 Getopt::Longがそれ以上の引数を処理しないようにするには、コマンドラインにダブルダッシュC<-->を挿入します。 (TBR) --size 24 -- --all =begin original In this example, C<--all> will I be treated as an option, but passed to the program unharmed, in C<@ARGV>. =end original この例では、C<--all>はオプションとして扱われますが、C<@ARGV>にそのままプログラムに渡されます。 (TBR) =head2 Options with values =begin original For options that take values it must be specified whether the option value is required or not, and what kind of value the option expects. =end original 値を取るオプションの場合は、オプション値が必須かどうか、およびオプションが期待する値の種類を指定する必要があります。 (TBR) =begin original Three kinds of values are supported: integer numbers, floating point numbers, and strings. =end original サポートされている値は、整数、浮動小数点数、文字列の3種類です。 (TBR) =begin original If the option value is required, Getopt::Long will take the command line argument that follows the option and assign this to the option variable. If, however, the option value is specified as optional, this will only be done if that value does not look like a valid command line option itself. =end original オプション値が必要な場合、Getopt::Longはオプションに続くコマンドライン引数を取り、これをオプション変数に代入します。 ただし、オプション値がオプションとして指定されている場合は、その値が有効なコマンドラインオプションではないと思われる場合にのみ、これが行われます。 (TBR) my $tag = ''; # option variable with default value GetOptions ('tag=s' => \$tag); =begin original In the option specification, the option name is followed by an equals sign C<=> and the letter C. The equals sign indicates that this option requires a value. The letter C indicates that this value is an arbitrary string. Other possible value types are C for integer values, and C for floating point values. Using a colon C<:> instead of the equals sign indicates that the option value is optional. In this case, if no suitable value is supplied, string valued options get an empty string C<''> assigned, while numeric options are set to C<0>. =end original オプション指定では、オプション名の後に等号C<=>と文字Cが続きます。 等号は、このオプションに値が必要であることを示します。 文字Cは、この値が任意の文字列であることを示します。 他に使用可能な値の型は、整数値の場合はC、浮動小数点値の場合はCです。 等号の代わりにコロンC<:>を使用すると、オプション値がオプションであることを示します。 この場合、適切な値が指定されていないと、文字列値のオプションには空の文字列C<''>が割り当てられ、数値オプションはC<0>に設定されます。 (TBR) =begin original (If the same option appears more than once on the command line, the last given value is used. If you want to take all the values, see below.) =end original (同じオプションがコマンドラインに複数回指定されている場合は、最後に指定された値が使用されます。 すべての値を取得する場合は、以下を参照してください。 ) (TBR) =head2 Options with multiple values =begin original Options sometimes take several values. For example, a program could use multiple directories to search for library files: =end original オプションは複数の値を取ることがあります。 たとえば、プログラムは複数のディレクトリを使用してライブラリファイルを検索できます。 (TBR) --library lib/stdlib --library lib/extlib =begin original To accomplish this behaviour, simply specify an array reference as the destination for the option: =end original この動作を実現するには、オプションの宛先として配列参照を指定するだけです。 (TBR) GetOptions ("library=s" => \@libfiles); =begin original Alternatively, you can specify that the option can have multiple values by adding a "@", and pass a reference to a scalar as the destination: =end original または、「@」を追加してオプションが複数の値を持つことを指定し、宛先としてスカラーへの参照を渡すこともできます。 (TBR) GetOptions ("library=s@" => \$libfiles); =begin original Used with the example above, C<@libfiles> c.q. C<@$libfiles> would contain two strings upon completion: C<"lib/stdlib"> and C<"lib/extlib">, in that order. It is also possible to specify that only integer or floating point numbers are acceptable values. =end original 上記の例で使用すると、C<@libfiles>c.q. C<@$libfiles>は、完了時にC<"lib/stdlib">とC<"lib/extlib">の2つの文字列をこの順序で含むことになります。 整数または浮動小数点数のみを有効な値として指定することもできます。 (TBR) =begin original Often it is useful to allow comma-separated lists of values as well as multiple occurrences of the options. This is easy using Perl's split() and join() operators: =end original 多くの場合、オプションの複数回の出現だけでなく、カンマで区切られた値のリストを許可すると便利です。 これは、Perlのsplit()およびjoin()演算子を使用すると簡単です。 (TBR) GetOptions ("library=s" => \@libfiles); @libfiles = split(/,/,join(',',@libfiles)); =begin original Of course, it is important to choose the right separator string for each purpose. =end original もちろん、目的ごとに適切な区切り文字列を選択することが重要です。 (TBR) =begin original Warning: What follows is an experimental feature. =end original 警告:以下は実験的な機能です。 (TBR) =begin original Options can take multiple values at once, for example =end original オプションは一度に複数の値をとることができます。 (TBR) --coordinates 52.2 16.4 --rgbcolor 255 255 149 =begin original This can be accomplished by adding a repeat specifier to the option specification. Repeat specifiers are very similar to the C<{...}> repeat specifiers that can be used with regular expression patterns. For example, the above command line would be handled as follows: =end original これは、オプション指定に繰り返し指定子を追加することで実現できます。 繰り返し指定子は、正規表現パターンで使用できるC<{.}>繰り返し指定子と非常によく似ています。 たとえば、上記のコマンドラインは次のように処理されます。 (TBR) GetOptions('coordinates=f{2}' => \@coor, 'rgbcolor=i{3}' => \@color); =begin original The destination for the option must be an array or array reference. =end original オプションの格納先は、配列または配列参照である必要があります。 (TBR) =begin original It is also possible to specify the minimal and maximal number of arguments an option takes. C indicates an option that takes at least two and at most 4 arguments. C indicates one or more values; C indicates zero or more option values. =end original オプションが取る引数の最小数と最大数を指定することもできます。 Cは、少なくとも2つ、多くても4つの引数を取るオプションを示します。 Cは1つ以上の値を示し、Cは0個以上のオプション値を示します。 (TBR) =head2 Options with hash values =begin original If the option destination is a reference to a hash, the option will take, as value, strings of the form IC<=>I. The value will be stored with the specified key in the hash. =end original オプションの宛先がハッシュへの参照である場合、オプションは値としてIC<=>Iの形式の文字列を取ります。 値は指定されたキーとともにハッシュに格納されます。 (TBR) GetOptions ("define=s" => \%defines); =begin original Alternatively you can use: =end original または、以下を使用することもできます。 (TBR) GetOptions ("define=s%" => \$defines); =begin original When used with command line options: =end original コマンドラインオプションとともに使用する場合: (TBR) --define os=linux --define vendor=redhat =begin original the hash C<%defines> (or C<%$defines>) will contain two keys, C<"os"> with value C<"linux"> and C<"vendor"> with value C<"redhat">. It is also possible to specify that only integer or floating point numbers are acceptable values. The keys are always taken to be strings. =end original ハッシュC<%defines>(またはC<%$defines>)は2つのキーを持ちます。 値C<"linux">のC<"os">と値C<"redhat">のC<"vendor">です。 整数または浮動小数点数だけが値として受け入れられるように指定することもできます。 キーは常に文字列と解釈されます。 (TBR) =head2 User-defined subroutines to handle options =begin original Ultimate control over what should be done when (actually: each time) an option is encountered on the command line can be achieved by designating a reference to a subroutine (or an anonymous subroutine) as the option destination. When GetOptions() encounters the option, it will call the subroutine with two or three arguments. The first argument is the name of the option. (Actually, it is an object that stringifies to the name of the option.) For a scalar or array destination, the second argument is the value to be stored. For a hash destination, the second argument is the key to the hash, and the third argument the value to be stored. It is up to the subroutine to store the value, or do whatever it thinks is appropriate. =end original コマンドラインでオプションに遭遇したとき(実際には毎回)に何をすべきかを最終的に制御するには、オプションの宛先としてサブルーチン(または匿名サブルーチン)への参照を指定します。 GetOptions()はオプションに遭遇すると、2つまたは3つの引数を使用してサブルーチンを呼び出します。 最初の引数はオプションの名前です(実際には、オプションの名前に文字列化されるオブジェクトです)。 スカラーまたは配列の宛先の場合、2番目の引数は格納される値です。 ハッシュの宛先の場合、2番目の引数はハッシュへのキーで、3番目の引数は格納される値です。 値を格納するか、適切と思われることを行うかは、サブルーチン次第です。 (TBR) =begin original A trivial application of this mechanism is to implement options that are related to each other. For example: =end original このメカニズムの簡単なアプリケーションは、相互に関連するオプションを実装することです。 次に例を示します。 (TBR) my $verbose = ''; # option variable with default value (false) GetOptions ('verbose' => \$verbose, 'quiet' => sub { $verbose = 0 }); =begin original Here C<--verbose> and C<--quiet> control the same variable C<$verbose>, but with opposite values. =end original ここで、C<--verbose>とC<--quiet>は同じ変数C<$verbose>を制御しますが、値は逆です。 (TBR) =begin original If the subroutine needs to signal an error, it should call die() with the desired error message as its argument. GetOptions() will catch the die(), issue the error message, and record that an error result must be returned upon completion. =end original サブルーチンがエラーを通知する必要がある場合は、目的のエラーメッセージを引数としてdie()を呼び出す必要があります。 GetOptions()はdie()をキャッチし、エラーメッセージを発行し、完了時にエラー結果を返す必要があることを記録します。 (TBR) =begin original If the text of the error message starts with an exclamation mark C it is interpreted specially by GetOptions(). There is currently one special command implemented: C will cause GetOptions() to stop processing options, as if it encountered a double dash C<-->. =end original エラーメッセージのテキストが感嘆符Cで始まる場合は、GetOptions()によって特別に解釈されます。 現在、1つの特別なコマンドが実装されています。 Cを実行すると、GetOptions()は、ダブルダッシュC<-->が発生したかのように、オプションの処理を停止します。 (TBR) =begin original Here is an example of how to access the option name and value from within a subroutine: =end original サブルーチン内からオプション名と値にアクセスする方法の例を次に示します。 (TBR) GetOptions ('opt=i' => \&handler); sub handler { my ($opt_name, $opt_value) = @_; print("Option name is $opt_name and value is $opt_value\n"); } =head2 Options with multiple names =begin original Often it is user friendly to supply alternate mnemonic names for options. For example C<--height> could be an alternate name for C<--length>. Alternate names can be included in the option specification, separated by vertical bar C<|> characters. To implement the above example: =end original 多くの場合、オプションの代替ニーモニック名を指定するのはユーザーフレンドリーです。 たとえば、C<--height>はC<--length>の代替名になります。 代替名はオプション指定に含めることができ、縦棒C<|>文字で区切られます。 前述の例を実装するには、次のようにします。 (TBR) GetOptions ('length|height=f' => \$length); =begin original The first name is called the I name, the other names are called I. When using a hash to store options, the key will always be the primary name. =end original 最初の名前はInameと呼ばれ、他の名前はIと呼ばれます。 ハッシュを使用してオプションを格納する場合、キーは常にプライマリ名になります。 (TBR) =begin original Multiple alternate names are possible. =end original 複数の代替名を使用できます。 (TBR) =head2 Case and abbreviations =begin original Without additional configuration, GetOptions() will ignore the case of option names, and allow the options to be abbreviated to uniqueness. =end original 追加の設定がない場合、GetOptions()はオプション名の大文字と小文字を無視し、オプションを一意に短縮することができます。 (TBR) GetOptions ('length|height=f' => \$length, "head" => \$head); =begin original This call will allow C<--l> and C<--L> for the length option, but requires a least C<--hea> and C<--hei> for the head and height options. =end original この呼び出しでは、長さオプションにC<--l>とC<--L>を使用できますが、頭と高さのオプションには少なくともC<--hea>とC<--hei>が必要です。 (TBR) =head2 Summary of Option Specifications =begin original Each option specifier consists of two parts: the name specification and the argument specification. =end original 各オプション指定子は、名前指定と引数指定の2つの部分で構成されます。 (TBR) =begin original The name specification contains the name of the option, optionally followed by a list of alternative names separated by vertical bar characters. The name is made up of alphanumeric characters, hyphens, underscores. If C is disabled, a period is also allowed in option names. =end original 名前の指定には、オプションの名前が含まれ、オプションの後に縦棒文字で区切られた代替名のリストが続く場合があります。 名前は、英数字、ハイフン、下線で構成されます。 Cが無効な場合は、オプション名にピリオドも使用できます。 (TBR) length option name is "length" length|size|l name is "length", aliases are "size" and "l" =begin original The argument specification is optional. If omitted, the option is considered boolean, a value of 1 will be assigned when the option is used on the command line. =end original 引数の指定はオプションです。 省略した場合、オプションはブール値とみなされ、コマンドラインで使用するときに値1が割り当てられます。 (TBR) =begin original The argument specification can be =end original 引数の指定には、次のものを使用できます。 (TBR) =over 4 =item ! =begin original The option does not take an argument and may be negated by prefixing it with "no" or "no-". E.g. C<"foo!"> will allow C<--foo> (a value of 1 will be assigned) as well as C<--nofoo> and C<--no-foo> (a value of 0 will be assigned). If the option has aliases, this applies to the aliases as well. =end original このオプションは引数を取らず、"no"または"no-"を前に付けることで否定できます。 たとえば、C<"foo!">は、C<--nofoo>とC<--no-foo>(値0が割り当てられます)だけでなく、C<--foo>(値1が割り当てられます)も許可します。 オプションにエイリアスがある場合、これはエイリアスにも適用されます。 (TBR) =begin original Using negation on a single letter option when bundling is in effect is pointless and will result in a warning. =end original バンドルが有効な場合に単一文字オプションに否定を使用しても意味がなく、警告が表示されます。 (TBR) =item + =begin original The option does not take an argument and will be incremented by 1 every time it appears on the command line. E.g. C<"more+">, when used with C<--more --more --more>, will increment the value three times, resulting in a value of 3 (provided it was 0 or undefined at first). =end original このオプションは引数を取らず、コマンドラインに表示されるたびに1ずつ増分されます。 たとえば、C<"more+">をC<--more --more --more>と一緒に使用すると、値が3倍になります(最初は0または未定義でした)。 (TBR) =begin original The C<+> specifier is ignored if the option destination is not a scalar. =end original オプションの出力先がスカラーでない場合、C<+>指定子は無視されます。 (TBR) =item = I [ I ] [ I ] =begin original The option requires an argument of the given type. Supported types are: =end original オプションには、指定したタイプの引数が必要です。 サポートされているタイプは次のとおりです: (TBR) =over 4 =item s =begin original String. An arbitrary sequence of characters. It is valid for the argument to start with C<-> or C<-->. =end original 文字列。 任意の文字列。 引数がC<->またはC<-->で始まる場合に有効です。 (TBR) =item i =begin original Integer. An optional leading plus or minus sign, followed by a sequence of digits. =end original 整数型(Integer)の値を指定します。 先頭にプラス記号またはマイナス記号(省略可能)を付け、その後に一連の数字を続けます。 (TBR) =item o =begin original Extended integer, Perl style. This can be either an optional leading plus or minus sign, followed by a sequence of digits, or an octal string (a zero, optionally followed by '0', '1', .. '7'), or a hexadecimal string (C<0x> followed by '0' .. '9', 'a' .. 'f', case insensitive), or a binary string (C<0b> followed by a series of '0' and '1'). =end original 拡張整数。 Perlスタイル。 先頭にプラス記号またはマイナス記号(省略可能)を付け、その後に一連の数字を続けるか、8進数文字列(0、その後に「0」、「1」、.「7」)、16進数文字列(C<0x>の後に「0」.「9」、「a」.「f」、大文字と小文字は区別されません)、またはバイナリ列(C<0b>の後に一連の「0」と「1」)を指定できます。 (TBR) =item f =begin original Real number. For example C<3.14>, C<-6.23E24> and so on. =end original 実数。 たとえば、C<3.14>、C<-6.23E24>など。 (TBR) =back =begin original The I can be C<@> or C<%> to specify that the option is list or a hash valued. This is only needed when the destination for the option value is not otherwise specified. It should be omitted when not needed. =end original Iには、C<@>またはC<%>を使用して、オプションがリストまたはハッシュ値であることを指定できます。 これは、オプション値の宛先が他に指定されていない場合にのみ必要です。 不要な場合は省略してください。 (TBR) =begin original The I specifies the number of values this option takes per occurrence on the command line. It has the format C<{> [ I ] [ C<,> [ I ] ] C<}>. =end original Iは、このオプションがコマンドラインで使用する値の数を指定します。 C<{>[I][C<,>[I]]C<}>の形式で指定します。 (TBR) =begin original I denotes the minimal number of arguments. It defaults to 1 for options with C<=> and to 0 for options with C<:>, see below. Note that I overrules the C<=> / C<:> semantics. =end original Iは引数の最小数を表します。 デフォルトはC<=>のオプションでは1、C<:>のオプションでは0です。 以下を参照してください。 IはC<=>/C<:>セマンティクスを無効にすることに注意してください。 (TBR) =begin original I denotes the maximum number of arguments. It must be at least I. If I is omitted, I, there is no upper bound to the number of argument values taken. =end original Iは、引数の最大数を表します。 I以上である必要があります。 Iを省略し、I<でもカンマが>でない場合、取得される引数値の数に上限はありません。 (TBR) =item : I [ I ] =begin original Like C<=>, but designates the argument as optional. If omitted, an empty string will be assigned to string values options, and the value zero to numeric options. =end original C<=>と似ていますが、引数をオプションとして指定します。 省略した場合、文字列値オプションには空の文字列が割り当てられ、数値オプションには0が割り当てられます。 (TBR) =begin original Note that if a string argument starts with C<-> or C<-->, it will be considered an option on itself. =end original 文字列引数がC<->またはC<-->で始まる場合、それ自体がオプションとみなされることに注意してください。 (TBR) =item : I [ I ] =begin original Like C<:i>, but if the value is omitted, the I will be assigned. =end original C<:i>と似ていますが、値を省略するとIが割り当てられます。 (TBR) =begin original If the I is octal, hexadecimal or binary, behaves like C<:o>. =end original Iが8進数、16進数、または2進数の場合、C<:o>のように動作します。 (TBR) =item : + [ I ] =begin original Like C<:i>, but if the value is omitted, the current value for the option will be incremented. =end original C<:i>と似ていますが、値を省略すると、オプションの現在の値が増分されます。 (TBR) =back =head1 Advanced Possibilities =head2 Object oriented interface =begin original See L. =end original Lを参照してください。 (TBR) =head2 Callback object =begin original In version 2.37 the first argument to the callback function was changed from string to object. This was done to make room for extensions and more detailed control. The object stringifies to the option name so this change should not introduce compatibility problems. =end original バージョン2.37では、コールバック関数の最初の引数がstringからobjectに変更されました。 これは、拡張とより詳細な制御のための領域を確保するために行われました。 オブジェクトはオプション名に文字列化されるため、この変更によって互換性の問題が発生することはありません。 (TBR) =begin original The callback object has the following methods: =end original コールバックオブジェクトには、次のメソッドがあります。 (TBR) =over =item name =begin original The name of the option, unabbreviated. For an option with multiple names it return the first (canonical) name. =end original 省略されていないオプションの名前。 複数の名前を持つオプションに対しては、最初の(正規の)名前を返します。 (TBR) =item given =begin original The name of the option as actually used, unabbreveated. =end original 実際に使用されているオプションの名前(省略なし)。 (TBR) =back =head2 Thread Safety =begin original Getopt::Long is thread safe when using ithreads as of Perl 5.8. It is I thread safe when using the older (experimental and now obsolete) threads implementation that was added to Perl 5.005. =end original Perl 5.8の時点でithreadを使用する場合、Getopt::Longはスレッドセーフです。 Perl 5.005に追加された古い(実験的で現在は廃止された)スレッド実装を使用する場合、Getopt::Longはスレッドセーフではありません。 (TBR) =head2 Documentation and help texts =begin original Getopt::Long encourages the use of Pod::Usage to produce help messages. For example: =end original Getopt::Longでは、Pod::Usageを使用してヘルプメッセージを生成することをお勧めします。 次に例を示します。 (TBR) use Getopt::Long; use Pod::Usage; my $man = 0; my $help = 0; GetOptions('help|?' => \$help, man => \$man) or pod2usage(2); pod2usage(1) if $help; pod2usage(-exitval => 0, -verbose => 2) if $man; __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 will read the given input file(s) and do something useful with the contents thereof. =cut =begin original See L for details. =end original 詳細は、Lを参照してください。 (TBR) =head2 Parsing options from an arbitrary array =begin original By default, GetOptions parses the options that are present in the global array C<@ARGV>. A special entry C can be used to parse options from an arbitrary array. =end original デフォルトでは、GetOptionsはグローバル配列C<@ARGV>に存在するオプションを解析します。 特別なエントリCは任意の配列からオプションを解析するために使用できます。 (TBR) use Getopt::Long qw(GetOptionsFromArray); $ret = GetOptionsFromArray(\@myopts, ...); =begin original When used like this, options and their possible values are removed from C<@myopts>, the global C<@ARGV> is not touched at all. =end original このように使用すると、オプションとそれらの可能な値はC<@myopts>から削除され、グローバルC<@ARGV>は全く変更されません。 (TBR) =begin original The following two calls behave identically: =end original 次の2つの呼び出しは同じように動作します。 (TBR) $ret = GetOptions( ... ); $ret = GetOptionsFromArray(\@ARGV, ... ); =begin original This also means that a first argument hash reference now becomes the second argument: =end original これは、最初の引数のハッシュ参照が2番目の引数になることも意味します。 (TBR) $ret = GetOptions(\%opts, ... ); $ret = GetOptionsFromArray(\@ARGV, \%opts, ... ); =head2 Parsing options from an arbitrary string =begin original A special entry C can be used to parse options from an arbitrary string. =end original 特殊なエントリCを使用して、任意の文字列からオプションを解析できます。 (TBR) use Getopt::Long qw(GetOptionsFromString); $ret = GetOptionsFromString($string, ...); =begin original The contents of the string are split into arguments using a call to C. As with C, the global C<@ARGV> is not touched. =end original 文字列の内容は、Cの呼び出しを使用して引数に分割されます。 Cと同様に、グローバルC<@ARGV>は変更されません。 (TBR) =begin original It is possible that, upon completion, not all arguments in the string have been processed. C will, when called in list context, return both the return status and an array reference to any remaining arguments: =end original 完了時に、文字列内のすべての引数が処理されていない可能性があります。 Cは、リストコンテキストで呼び出されると、リターンステータスと、残りの引数への配列参照の両方を返します。 (TBR) ($ret, $args) = GetOptionsFromString($string, ... ); =begin original If any arguments remain, and C was not called in list context, a message will be given and C will return failure. =end original 引数が残っていて、リストコンテキストでCが呼び出されなかった場合、メッセージが表示され、Cは失敗を返します。 (TBR) =begin original As with GetOptionsFromArray, a first argument hash reference now becomes the second argument. See the next section. =end original GetOptionsFromArrayと同様に、最初の引数のハッシュ参照が2番目の引数になるようになりました。 次のセクションを参照してください。 (TBR) =head2 Storing options values in a hash =begin original Sometimes, for example when there are a lot of options, having a separate variable for each of them can be cumbersome. GetOptions() supports, as an alternative mechanism, storing options values in a hash. =end original 場合によっては、たとえばオプションが多数ある場合、それぞれに個別の変数を使用するのが面倒になることがあります。 GetOptions()は、代替メカニズムとして、オプション値をハッシュに格納することをサポートします。 (TBR) =begin original To obtain this, a reference to a hash must be passed I to GetOptions(). For each option that is specified on the command line, the option value will be stored in the hash with the option name as key. Options that are not actually used on the command line will not be put in the hash, on other words, C (or defined()) can be used to test if an option was used. The drawback is that warnings will be issued if the program runs under C and uses C<$h{option}> without testing with exists() or defined() first. =end original これを取得するには、ハッシュへの参照をI<最初の引数として>GetOptions()に渡す必要があります。 コマンドラインで指定された各オプションの値は、キーとしてオプション名とともにハッシュに格納されます。 コマンドラインで実際に使用されないオプションはハッシュに格納されません。 つまり、C(またはdefined())を使用して、オプションが使用されたかどうかをテストできます。 欠点は、プログラムがCの下で実行され、最初にexists()またはdefined()を使用してテストせずにC<$h{option}>を使用する場合に警告が発行されることです。 (TBR) my %h = (); GetOptions (\%h, 'length=i'); # will store in $h{length} =begin original For options that take list or hash values, it is necessary to indicate this by appending an C<@> or C<%> sign after the type: =end original リストまたはハッシュ値をとるオプションでは、型の後にC<@>またはC<%>記号を追加することでこれを示す必要があります。 (TBR) GetOptions (\%h, 'colours=s@'); # will push to @{$h{colours}} =begin original To make things more complicated, the hash may contain references to the actual destinations, for example: =end original さらに複雑にするために、ハッシュには実際の宛先への参照が含まれる場合があります。 次に例を示します。 (TBR) my $len = 0; my %h = ('length' => \$len); GetOptions (\%h, 'length=i'); # will store in $len =begin original This example is fully equivalent with: =end original この例は、次と完全に同等です。 (TBR) my $len = 0; GetOptions ('length=i' => \$len); # will store in $len =begin original Any mixture is possible. For example, the most frequently used options could be stored in variables while all other options get stored in the hash: =end original 任意の組み合わせが可能です。 たとえば、最も頻繁に使用されるオプションは変数に格納され、他のすべてのオプションはハッシュに格納されます。 (TBR) my $verbose = 0; # frequently referred my $debug = 0; # frequently referred my %h = ('verbose' => \$verbose, 'debug' => \$debug); GetOptions (\%h, 'verbose', 'debug', 'filter', 'size=i'); if ( $verbose ) { ... } if ( exists $h{filter} ) { ... option 'filter' was specified ... } =head2 Bundling =begin original With bundling it is possible to set several single-character options at once. For example if C, C and C are all valid options, =end original バンドルを使用すると、複数の単一文字オプションを一度に設定できます。 たとえば、C、C、およびCがすべて有効なオプションである場合 (TBR) -vax =begin original will set all three. =end original は3つすべてを設定します。 (TBR) =begin original Getopt::Long supports three styles of bundling. To enable bundling, a call to Getopt::Long::Configure is required. =end original Getopt::Longは、3つのバンドルスタイルをサポートしています。 バンドルを有効にするには、Getopt::Long::Configureを呼び出す必要があります。 (TBR) =begin original The simplest style of bundling can be enabled with: =end original 最も単純なスタイルのバンドルは、次のようにして有効にできます。 (TBR) Getopt::Long::Configure ("bundling"); =begin original Configured this way, single-character options can be bundled but long options (and any of their auto-abbreviated shortened forms) B always start with a double dash C<--> to avoid ambiguity. For example, when C, C, C and C are all valid options, =end original このように設定すると、1文字のオプションを束ねることができますが、長いオプション(および自動省略の短縮形)Bは、あいまいさを避けるために常にダブルダッシュC<-->で始まります。 たとえば、C、C、C、およびCがすべて有効なオプションである場合 (TBR) -vax =begin original will set C, C and C, but =end original はC,C,Cを設定するが (TBR) --vax =begin original will set C. =end original はCを設定する。 (TBR) =begin original The second style of bundling lifts this restriction. It can be enabled with: =end original 2番目のバンドルスタイルでは、この制限が解除されます。 これは次の方法で有効にできます。 (TBR) Getopt::Long::Configure ("bundling_override"); =begin original Now, C<-vax> will set the option C. =end original ここで、C<-vax>はオプションCをセットする。 (TBR) =begin original In all of the above cases, option values may be inserted in the bundle. For example: =end original 上記のすべての場合において、オプション値をバンドルに挿入できます。 例: (TBR) -h24w80 =begin original is equivalent to =end original と同じです。 (TBR) -h 24 -w 80 =begin original A third style of bundling allows only values to be bundled with options. It can be enabled with: =end original バンドルの3番目のスタイルでは、値のみをオプションとバンドルできます。 これは次の方法で有効にできます。 (TBR) Getopt::Long::Configure ("bundling_values"); =begin original Now, C<-h24> will set the option C to C<24>, but option bundles like C<-vxa> and C<-h24w80> are flagged as errors. =end original 現在、C<-h24>はオプションCをC<24>に設定しますが、C<-vxa>やC<-h24w80>のようなオプションバンドルはエラーとしてフラグが立てられます。 (TBR) =begin original Enabling C will disable the other two styles of bundling. =end original Cを有効にすると、他の2つのバンドル方式が無効になります。 (TBR) =begin original When configured for bundling, single-character options are matched case sensitive while long options are matched case insensitive. To have the single-character options matched case insensitive as well, use: =end original バンドル用に設定されている場合、1文字のオプションは大文字と小文字を区別し、長いオプションは大文字と小文字を区別しません。 1文字のオプションも大文字と小文字を区別しないようにするには、次のように指定します。 (TBR) Getopt::Long::Configure ("bundling", "ignorecase_always"); =begin original It goes without saying that bundling can be quite confusing. =end original 言うまでもなく、バンドルは非常に混乱を招く可能性があります。 (TBR) =head2 The lonesome dash =begin original Normally, a lone dash C<-> on the command line will not be considered an option. Option processing will terminate (unless "permute" is configured) and the dash will be left in C<@ARGV>. =end original 通常、コマンドラインの単独のダッシュC<->はオプションとはみなされません。 オプション処理は終了し("permute"が設定されていない限り)、ダッシュはC<@ARGV>のままになります。 (TBR) =begin original It is possible to get special treatment for a lone dash. This can be achieved by adding an option specification with an empty name, for example: =end original 単発の場合は特別な治療を受けることができます。 これは、空の名前を持つオプション仕様を追加することで実現できます。 例: (TBR) GetOptions ('' => \$stdio); =begin original A lone dash on the command line will now be a legal option, and using it will set variable C<$stdio>. =end original コマンドラインの一文字のダッシュは正しいオプションとなり、これを使用すると変数C<$stdio>が設定されます。 (TBR) =head2 Argument callback =begin original A special option 'name' C<< <> >> can be used to designate a subroutine to handle non-option arguments. When GetOptions() encounters an argument that does not look like an option, it will immediately call this subroutine and passes it one parameter: the argument name. =end original 特殊なオプション'name'C<<<>>>を使用して、オプション以外の引数を処理するサブルーチンを指定できます。 GetOptions()は、オプションのように見えない引数を検出すると、すぐにこのサブルーチンを呼び出し、引数名という1つのパラメータを渡します。 (TBR) =begin original For example: =end original 次に例を示します。 (TBR) my $width = 80; sub process { ... } GetOptions ('width=i' => \$width, '<>' => \&process); =begin original When applied to the following command line: =end original 次のコマンドラインに適用した場合: (TBR) arg1 --width=72 arg2 --width=60 arg3 =begin original This will call C while C<$width> is C<80>, C while C<$width> is C<72>, and C while C<$width> is C<60>. =end original これにより、C<$width>がC<80>の場合はC、C<$width>がC<72>の場合はC、C<$width>がC<60>の場合はCが呼び出されます。 (TBR) =begin original This feature requires configuration option B, see section L. =end original この機能には設定オプションBが必要です。 セクションLを参照してください。 (TBR) =head1 Configuring Getopt::Long =begin original Getopt::Long can be configured by calling subroutine Getopt::Long::Configure(). This subroutine takes a list of quoted strings, each specifying a configuration option to be enabled, e.g. C. To disable, prefix with C or C, e.g. C. Case does not matter. Multiple calls to Configure() are possible. =end original Getopt::Longは、サブルーチンGetopt::Long::Configure()を呼び出すことで設定できます。 このサブルーチンは、引用符で囲まれた文字列のリストを受け取り、それぞれが有効にする設定オプションを指定します。 たとえば、Cです。 無効にするには、CまたはCでプレフィックスします。 たとえば、Cです。 大文字と小文字は区別されません。 Configure()は複数回呼び出すことができます。 (TBR) =begin original Alternatively, as of version 2.24, the configuration options may be passed together with the C statement: =end original あるいは、バージョン2.24では、設定オプションをC文と一緒に渡すこともできます。 (TBR) use Getopt::Long qw(:config no_ignore_case bundling); =begin original The following options are available: =end original 次のオプションを使用できます。 (TBR) =over 12 =item default =begin original This option causes all configuration options to be reset to their default values. =end original このオプションを使用すると、すべてのコンフィギュレーションオプションがデフォルト値にリセットされます。 (TBR) =item posix_default =begin original This option causes all configuration options to be reset to their default values as if the environment variable POSIXLY_CORRECT had been set. =end original このオプションは、環境変数POSIXLY_CORRECTが設定されているかのように、すべての構成オプションをデフォルト値にリセットします。 (TBR) =item auto_abbrev =begin original Allow option names to be abbreviated to uniqueness. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case C is disabled. =end original オプション名を一意に短縮できるようにします。 環境変数POSIXLY_CORRECTが設定されていない限り、デフォルトは有効です。 環境変数POSIXLY_CORRECTが設定されている場合、Cは無効になります。 (TBR) =item getopt_compat =begin original Allow C<+> to start options. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case C is disabled. =end original C<+>でオプションを開始できるようにします。 環境変数POSIXLY_CORRECTが設定されていない限り、デフォルトは有効です。 環境変数POSIXLY_CORRECTが設定されている場合、Cは無効になります。 (TBR) =item gnu_compat =begin original C controls whether C<--opt=> is allowed, and what it should do. Without C, C<--opt=> gives an error. With C, C<--opt=> will give option C an empty value. This is the way GNU getopt_long() does it. =end original Cは、C<--opt=>を許可するかどうか、そして何をすべきかを制御します。 Cがなければ、C<--opt=>はエラーになります。 Cがあれば、C<--opt=>はオプションCに空の値を与えます。 これはGNU getopt_long()が行う方法です。 (TBR) =begin original Note that for options with optional arguments, C<--opt value> is still accepted, even though GNU getopt_long() requires writing C<--opt=value> in this case. =end original GNUのgetopt_long()ではC<--opt=value>を記述する必要がありますが、オプション引数を持つオプションでは、C<--opt value>も受け入れられることに注意してください。 (TBR) =item gnu_getopt =begin original This is a short way of setting C C C C. With C, command line handling should be reasonably compatible with GNU getopt_long(). =end original これはCCCCを設定する簡単な方法です。 Cでは、コマンドライン処理はGNU getopt_long()と適度に互換性があるはずです。 (TBR) =item require_order =begin original Whether command line arguments are allowed to be mixed with options. Default is disabled unless environment variable POSIXLY_CORRECT has been set, in which case C is enabled. =end original コマンドライン引数とオプションを混在させることができるかどうか。 環境変数POSIXLY_CORRECTが設定されていない限り、デフォルトは無効です。 環境変数POSIXLY_CORRECTが設定されている場合は、Cが有効になります。 (TBR) =begin original See also C, which is the opposite of C. =end original Cの逆であるCも参照してください。 (TBR) =item permute =begin original Whether command line arguments are allowed to be mixed with options. Default is enabled unless environment variable POSIXLY_CORRECT has been set, in which case C is disabled. Note that C is the opposite of C. =end original コマンドライン引数をオプションと混在させることができるかどうか。 環境変数POSIXLY_CORRECTが設定されていない限り、デフォルトは有効です。 環境変数POSIXLY_CORRECTが設定されている場合、Cは無効になります。 CはCの逆であることに注意してください。 (TBR) =begin original If C is enabled, this means that =end original Cが有効になっていると (TBR) --foo arg1 --bar arg2 arg3 =begin original is equivalent to =end original と同じです。 (TBR) --foo --bar arg1 arg2 arg3 =begin original If an argument callback routine is specified, C<@ARGV> will always be empty upon successful return of GetOptions() since all options have been processed. The only exception is when C<--> is used: =end original 引き数コールバックルーチンが指定される場合、C<@ARGV>は、すべてのオプションが処理されているので、GetOptions()が正常に戻されると常に空になります。 唯一の例外は、C<-->が使用される場合です: (TBR) --foo arg1 --bar arg2 -- arg3 =begin original This will call the callback routine for arg1 and arg2, and then terminate GetOptions() leaving C<"arg3"> in C<@ARGV>. =end original これはarg1とarg2のためのコールバックルーチンを呼び出し、C<"arg3">をC<@ARGV>に残してGetOptions()を終了します。 (TBR) =begin original If C is enabled, options processing terminates when the first non-option is encountered. =end original Cが有効になっている場合、オプション処理は、最初の非オプションに遭遇したときに終了します。 (TBR) --foo arg1 --bar arg2 arg3 =begin original is equivalent to =end original と同じです。 (TBR) --foo -- arg1 --bar arg2 arg3 =begin original If C is also enabled, options processing will terminate at the first unrecognized option, or non-option, whichever comes first. =end original Cも有効になっている場合、オプションの処理は最初の認識されないオプション、またはオプションでないもののどちらか早い方で終了します。 (TBR) =item bundling (default: disabled) =begin original Enabling this option will allow single-character options to be bundled. To distinguish bundles from long option names, long options (and any of their auto-abbreviated shortened forms) I be introduced with C<--> and bundles with C<->. =end original このオプションを有効にすると、1文字のオプションをバンドルすることができます。 バンドルを長いオプション名と区別するために、長いオプション(およびそれらの自動省略された短縮形)IはC<-->で導入され、バンドルはC<->で導入されます。 (TBR) =begin original Note that, if you have options C, C and C, and auto_abbrev enabled, possible arguments and option settings are: =end original オプションC、C、およびCがあり、auto_abbrevが有効になっている場合、使用できる引数とオプション設定は次のとおりです。 (TBR) using argument sets option(s) ------------------------------------------ -a, --a a -l, --l l -al, -la, -ala, -all,... a, l --al, --all all =begin original The surprising part is that C<--a> sets option C (due to auto completion), not C. =end original 驚くべき点は、C<--a>がオプションCを設定するのであって(自動補完のため)、Cではないことである。 (TBR) =begin original Note: disabling C also disables C. =end original 注意:Cを無効にすると、Cも無効になります。 (TBR) =item bundling_override (default: disabled) =begin original If C is enabled, bundling is enabled as with C but now long option names override option bundles. =end original Cが有効な場合、Cと同様にバンドルが有効になりますが、長いオプション名がオプションバンドルを上書きするようになりました。 (TBR) =begin original Note: disabling C also disables C. =end original 注意:Cを無効にすると、Cも無効になります。 (TBR) =begin original B Using option bundling can easily lead to unexpected results, especially when mixing long options and bundles. Caveat emptor. =end original B<注:>オプションのバンドル化を使用すると、特に長いオプションとバンドルを混在させる場合に、予期しない結果が簡単に発生する可能性があります。 買手側の注意。 (TBR) =item ignore_case (default: enabled) =begin original If enabled, case is ignored when matching option names. If, however, bundling is enabled as well, single character options will be treated case-sensitive. =end original 有効にすると、オプション名の照合時に大文字と小文字が無視されます。 ただし、バンドルも有効にすると、1文字のオプションは大文字と小文字が区別されます。 (TBR) =begin original With C, option specifications for options that only differ in case, e.g., C<"foo"> and C<"Foo">, will be flagged as duplicates. =end original Cでは、C<"foo">とC<"Foo">のように大文字と小文字が異なるだけのオプションの指定は、重複としてフラグが立てられます。 (TBR) =begin original Note: disabling C also disables C. =end original 注意:Cを無効にすると、Cも無効になります。 (TBR) =item ignore_case_always (default: disabled) =begin original When bundling is in effect, case is ignored on single-character options also. =end original バンドルが有効な場合、1文字のオプションでも大文字と小文字は無視されます。 (TBR) =begin original Note: disabling C also disables C. =end original 注意:Cを無効にすると、Cも無効になります。 (TBR) =item auto_version (default:disabled) =begin original Automatically provide support for the B<--version> option if the application did not specify a handler for this option itself. =end original アプリケーションがB<--version>オプション自体のハンドラを指定しなかった場合に、このオプションのサポートを自動的に提供します。 (TBR) =begin original Getopt::Long will provide a standard version message that includes the program name, its version (if $main::VERSION is defined), and the versions of Getopt::Long and Perl. The message will be written to standard output and processing will terminate. =end original Getopt::Longは、プログラム名、そのバージョン($main::VERSIONが定義されている場合)、およびGetopt::LongとPerlのバージョンを含む標準バージョンメッセージを提供します。 メッセージは標準出力に書き込まれ、処理は終了します。 (TBR) =begin original C will be enabled if the calling program explicitly specified a version number higher than 2.32 in the C or C statement. =end original Cは、呼び出し元のプログラムがCまたはC文で2.32より大きいバージョン番号を明示的に指定した場合に有効になります。 (TBR) =item auto_help (default:disabled) =begin original Automatically provide support for the B<--help> and B<-?> options if the application did not specify a handler for this option itself. =end original アプリケーションがB<--help>およびB<-?>オプション自体のハンドラを指定しなかった場合に、このオプションのサポートを自動的に提供します。 (TBR) =begin original Getopt::Long will provide a help message using module L. The message, derived from the SYNOPSIS POD section, will be written to standard output and processing will terminate. =end original Getopt::Longは、モジュールLを使用してヘルプメッセージを提供します。 SYNOPSIS PODセクションから派生したメッセージは標準出力に書き込まれ、処理が終了します。 (TBR) =begin original C will be enabled if the calling program explicitly specified a version number higher than 2.32 in the C or C statement. =end original Cは、呼び出し元のプログラムがCまたはC文で2.32より大きいバージョン番号を明示的に指定した場合に有効になります。 (TBR) =item pass_through (default: disabled) =begin original With C anything that is unknown, ambiguous or supplied with an invalid option will not be flagged as an error. Instead the unknown option(s) will be passed to the catchall C<< <> >> if present, otherwise through to C<@ARGV>. This makes it possible to write wrapper scripts that process only part of the user supplied command line arguments, and pass the remaining options to some other program. =end original Cでは、不明なもの、あいまいなもの、無効なオプションが指定されたものはエラーとしてフラグ付けされません。 代わりに、不明なオプションはキャッチオールC<<<>>>があればそれに渡され、なければC<@ARGV>に渡されます。 これにより、ユーザが指定したコマンドライン引数の一部だけを処理し、残りのオプションを他のプログラムに渡すラッパースクリプトを書くことができます。 (TBR) =begin original If C is enabled, options processing will terminate at the first unrecognized option, or non-option, whichever comes first and all remaining arguments are passed to C<@ARGV> instead of the catchall C<< <> >> if present. However, if C is enabled instead, results can become confusing. =end original Cが有効な場合、オプション処理は最初の認識できないオプション、またはオプションでないもののうち最初に来たもので終了し、全ての残りの引数はC<<<>>の代わりにC<@ARGV>に渡されます。 しかし、もしCが有効な場合、結果が混乱するかもしれません。 (TBR) =begin original Note that the options terminator (default C<-->), if present, will also be passed through in C<@ARGV>. =end original もし存在するなら、オプション終端文字(デフォルトC<-->)はC<@ARGV>でもパススルーされることに注意してください。 (TBR) =item prefix =begin original The string that starts options. If a constant string is not sufficient, see C. =end original オプションを開始する文字列。 定数文字列が十分でない場合は、Cを参照してください。 (TBR) =item prefix_pattern =begin original A Perl pattern that identifies the strings that introduce options. Default is C<--|-|\+> unless environment variable POSIXLY_CORRECT has been set, in which case it is C<--|->. =end original オプションを導入する文字列を識別するPerlパターン。 環境変数POSIXLY_CORRECTが設定されていない限り、デフォルトはC<--|-|\+>です。 環境変数POSIXLY_CORRECTが設定されている場合は、C<--|->です。 (TBR) =item long_prefix_pattern =begin original A Perl pattern that allows the disambiguation of long and short prefixes. Default is C<-->. =end original 長い接頭部と短い接頭部を区別できるPerlパターン。 デフォルトはC<-->です。 (TBR) =begin original Typically you only need to set this if you are using nonstandard prefixes and want some or all of them to have the same semantics as '--' does under normal circumstances. =end original 通常、これを設定する必要があるのは、非標準のプレフィックスを使用していて、その一部またはすべてを通常の状況での'--'と同じセマンティクスにしたい場合だけです。 (TBR) =begin original For example, setting prefix_pattern to C<--|-|\+|\/> and long_prefix_pattern to C<--|\/> would add Win32 style argument handling. =end original たとえば、prefix_patternをC<--|-|\+|\/>に設定し、long_prefix_patternをC<--|\/>に設定すると、Win32スタイルの引数処理が追加されます。 (TBR) =item debug (default: disabled) =begin original Enable debugging output. =end original デバッグ出力を有効にします。 (TBR) =back =head1 Exportable Methods =over =item VersionMessage =begin original This subroutine provides a standard version message. Its argument can be: =end original このサブルーチンは、標準バージョンのメッセージを提供します。 引数は次のいずれかです。 (TBR) =over 4 =item * =begin original A string containing the text of a message to print I printing the standard message. =end original 標準メッセージを表示するIを出力するメッセージのテキストを含む文字列。 (TBR) =item * =begin original A numeric value corresponding to the desired exit status. =end original 目的の終了ステータスに対応する数値。 (TBR) =item * =begin original A reference to a hash. =end original ハッシュへの参照。 (TBR) =back =begin original If more than one argument is given then the entire argument list is assumed to be a hash. If a hash is supplied (either as a reference or as a list) it should contain one or more elements with the following keys: =end original 複数の引数が指定された場合、引数リスト全体がハッシュとみなされます。 ハッシュが(参照またはリストとして)指定された場合、次のキーを持つ1つ以上の要素が含まれている必要があります。 (TBR) =over 4 =item C<-message> =item C<-msg> =begin original The text of a message to print immediately prior to printing the program's usage message. =end original プログラムの使用状況メッセージを表示する直前に表示するメッセージのテキストです。 (TBR) =item C<-exitval> =begin original The desired exit status to pass to the B function. This should be an integer, or else the string "NOEXIT" to indicate that control should simply be returned without terminating the invoking process. =end original B関数に渡す終了ステータス。 整数値、または文字列"NOEXIT"を指定します。 文字列を指定すると、呼び出し元のプロセスを終了せずに制御を返すことを示します。 (TBR) =item C<-output> =begin original A reference to a filehandle, or the pathname of a file to which the usage message should be written. The default is C<\*STDERR> unless the exit value is less than 2 (in which case the default is C<\*STDOUT>). =end original ファイルハンドルへの参照、または使用状況メッセージの書き込み先となるファイルのパス名。 終了値が2より小さい場合(この場合のデフォルトはC<\*STDOUT>)を除き、デフォルトはC<\*STDERR>である。 (TBR) =back =begin original You cannot tie this routine directly to an option, e.g.: =end original このルーチンを直接オプションに関連付けることはできません。 例: (TBR) GetOptions("version" => \&VersionMessage); =begin original Use this instead: =end original 代わりにこれを使用します。 (TBR) GetOptions("version" => sub { VersionMessage() }); =item HelpMessage =begin original This subroutine produces a standard help message, derived from the program's POD section SYNOPSIS using L. It takes the same arguments as VersionMessage(). In particular, you cannot tie it directly to an option, e.g.: =end original このサブルーチンは、Lを使用して、プログラムのPODセクションのSYNOPSISから派生した標準のヘルプメッセージを生成します。 VersionMessage()と同じ引数を取ります。 特に、次のようにオプションに直接結び付けることはできません。 (TBR) GetOptions("help" => \&HelpMessage); =begin original Use this instead: =end original 代わりにこれを使用します。 (TBR) GetOptions("help" => sub { HelpMessage() }); =back =head1 Return values and Errors =begin original Configuration errors and errors in the option definitions are signalled using die() and will terminate the calling program unless the call to Getopt::Long::GetOptions() was embedded in C, or die() was trapped using C<$SIG{__DIE__}>. =end original 設定エラーとオプション定義のエラーはdie()を使用して通知され、Getopt::Long::GetOptions()の呼び出しがCに埋め込まれているか、die()がC<$SIG{__DIE__}>を使用してトラップされていない限り、呼び出し元のプログラムを終了します。 (TBR) =begin original GetOptions returns true to indicate success. It returns false when the function detected one or more errors during option parsing. These errors are signalled using warn() and can be trapped with C<$SIG{__WARN__}>. =end original GetOptionsは、成功した場合にtrueを返します。 関数がオプションの解析中に1つ以上のエラーを検出した場合はfalseを返します。 これらのエラーはwarn()を使用して通知され、C<$SIG{__WARN__}>でトラップできます。 (TBR) =head1 Legacy =begin original The earliest development of C started in 1990, with Perl version 4. As a result, its development, and the development of Getopt::Long, has gone through several stages. Since backward compatibility has always been extremely important, the current version of Getopt::Long still supports a lot of constructs that nowadays are no longer necessary or otherwise unwanted. This section describes briefly some of these 'features'. =end original Cの最も初期の開発は、1990年にPerlバージョン4で始まりました。 その結果、その開発とGetopt::Longの開発は、いくつかの段階を経てきました。 下位互換性は常に非常に重要であったため、現在のバージョンのGetopt::Longは、現在では不要になった、あるいは望ましくない多くの構成体をサポートしています。 このセクションでは、これらの「機能」のいくつかについて簡単に説明します。 (TBR) =head2 Default destinations =begin original When no destination is specified for an option, GetOptions will store the resultant value in a global variable named CI, where I is the primary name of this option. When a program executes under C (recommended), these variables must be pre-declared with our(). =end original オプションに出力先が指定されていない場合、GetOptionsは、結果の値をCIという名前のグローバル変数に格納します。 Iは、このオプションのプライマリ名です。 プログラムをC(推奨)で実行する場合は、これらの変数を()で事前に宣言しておく必要があります。 (TBR) our $opt_length = 0; GetOptions ('length=i'); # will store in $opt_length =begin original To yield a usable Perl variable, characters that are not part of the syntax for variables are translated to underscores. For example, C<--fpp-struct-return> will set the variable C<$opt_fpp_struct_return>. Note that this variable resides in the namespace of the calling program, not necessarily C
. For example: =end original 使用可能なPerl変数を生成するために、変数の構文の一部ではない文字はアンダースコアに変換されます。 たとえば、C<--fpp-struct-return>は、変数C<$opt_fpp_struct_return>を設定します。 この変数は、必ずしもC
ではなく、呼び出し元プログラムのネームスペースに存在することに注意してください。 例: (TBR) GetOptions ("size=i", "sizes=i@"); =begin original with command line "-size 10 -sizes 24 -sizes 48" will perform the equivalent of the assignments =end original コマンド行に"-size 10-sizes 24-sizes 48"と指定すると (TBR) $opt_size = 10; @opt_sizes = (24, 48); =head2 Alternative option starters =begin original A string of alternative option starter characters may be passed as the first argument (or the first argument after a leading hash reference argument). =end original 最初の引数(もしくは、先行するハッシュ参照引数の後の最初の引数)として、複数選択可能なオプション開始文字の文字列を渡すことができます。 (TBR) my $len = 0; GetOptions ('/', 'length=i' => $len); =begin original Now the command line may look like: =end original コマンドラインは次のようになります。 (TBR) /length 24 -- arg =begin original Note that to terminate options processing still requires a double dash C<-->. =end original オプション処理を終了するには、依然としてダブルダッシュC<-->が必要であることに注意してください。 (TBR) =begin original GetOptions() will not interpret a leading C<< "<>" >> as option starters if the next argument is a reference. To force C<< "<" >> and C<< ">" >> as option starters, use C<< "><" >>. Confusing? Well, B anyway. =end original GetOptions()は、次の引数が参照の場合、先頭のC<<"<>">>をオプションスターターとして解釈しません。 C<<"<" >>とC<<" >">>をオプションスターターとして強制するには、C<<" ><" >>を使用してください。 混乱しますか?まあ、B<スターター引数を使用することは強く推奨されません>。 (TBR) =head2 Configuration variables =begin original Previous versions of Getopt::Long used variables for the purpose of configuring. Although manipulating these variables still work, it is strongly encouraged to use the C routine that was introduced in version 2.17. Besides, it is much easier. =end original 以前のバージョンのGetopt::Longでは、設定のために変数を使用していました。 これらの変数を操作することはできますが、バージョン2.17で導入されたCルーチンを使用することを強くお勧めします。 しかも、はるかに簡単です。 (TBR) =head1 Tips and Techniques =head2 Pushing multiple values in a hash option =begin original Sometimes you want to combine the best of hashes and arrays. For example, the command line: =end original 場合によっては、ハッシュと配列の最良の部分を組み合わせたい場合があります。 たとえば、コマンドラインは次のとおりです: (TBR) --list add=first --list add=second --list add=third =begin original where each successive 'list add' option will push the value of add into array ref $list->{'add'}. The result would be like =end original ここで、それぞれの連続した'list add'オプションは、addの値を配列ref$list->{'add'}にプッシュします。 結果は次のようになります。 (TBR) $list->{add} = [qw(first second third)]; =begin original This can be accomplished with a destination routine: =end original これは、宛先ルーチンを使用して行うことができます。 (TBR) GetOptions('list=s%' => sub { push(@{$list{$_[1]}}, $_[2]) }); =head1 Troubleshooting =head2 GetOptions does not return a false result when an option is not supplied =begin original That's why they're called 'options'. =end original それが「オプション」と呼ばれる理由です。 (TBR) =head2 GetOptions does not split the command line correctly =begin original The command line is not split by GetOptions, but by the command line interpreter (CLI). On Unix, this is the shell. On Windows, it is COMMAND.COM or CMD.EXE. Other operating systems have other CLIs. =end original コマンドラインは、GetOptionsではなく、コマンドラインインタープリタ(CLI)によって分割されます。 Unixでは、これはシェルです。 WindowsではCOMMAND.COMまたはCMD.EXEです。 他のオペレーティングシステムには他のCLIがあります。 (TBR) =begin original It is important to know that these CLIs may behave different when the command line contains special characters, in particular quotes or backslashes. For example, with Unix shells you can use single quotes (C<'>) and double quotes (C<">) to group words together. The following alternatives are equivalent on Unix: =end original コマンドラインに特殊文字(特に引用符やバックスラッシュ)が含まれている場合、これらのCLIの動作が異なる場合があることに注意してください。 たとえば、Unixシェルでは、一重引用符(C<'>)と二重引用符(C<">)を使用して単語をグループ化できます。 次の選択肢は、Unixでも同じです。 (TBR) "two words" 'two words' two\ words =begin original In case of doubt, insert the following statement in front of your Perl program: =end original 疑問がある場合は、Perlプログラムの前に次のステートメントを挿入してください。 (TBR) print STDERR (join("|",@ARGV),"\n"); =begin original to verify how your CLI passes the arguments to the program. =end original CLIがどのように引数をプログラムに渡すかを確認します。 (TBR) =head2 Undefined subroutine &main::GetOptions called =begin original Are you running Windows, and did you write =end original あなたはWindowsを使っていますか? (TBR) use GetOpt::Long; =begin original (note the capital 'O')? =end original (大文字の「O」に注意)? (TBR) =head2 How do I put a "-?" option into a Getopt::Long? =begin original You can only obtain this using an alias, and Getopt::Long of at least version 2.13. =end original これを取得するには、エイリアスとバージョン2.13以降のGetopt::Longを使用する必要があります。 (TBR) use Getopt::Long; GetOptions ("help|?"); # -help and -? will both set $opt_help =begin original Other characters that can't appear in Perl identifiers are also supported in aliases with Getopt::Long of at version 2.39. Note that the characters C, C<|>, C<+>, C<=>, and C<:> can only appear as the first (or only) character of an alias. =end original バージョン2.39のGetopt::Longのエイリアスでは、Perl識別子に表示できないその他の文字もサポートされています。 C、C<|>、C<+>、C<=>、およびC<:>の文字は、エイリアスの最初(または唯一)の文字としてのみ表示できることに注意してください。 (TBR) =begin original As of version 2.32 Getopt::Long provides auto-help, a quick and easy way to add the options --help and -? to your program, and handle them. =end original バージョン2.32では、Getopt::Longは自動ヘルプを提供しています。 これは、--helpと--?のオプションをプログラムに追加し、それらを処理するための迅速で簡単な方法です。 (TBR) =begin original See C in section L. =end original Lの節のCを参照してください。 (TBR) =head1 AUTHOR Johan Vromans =head1 COPYRIGHT AND DISCLAIMER This program is Copyright 1990,2015,2023 by Johan Vromans. This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. If you do not have a copy of the GNU General Public License write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. =cut =begin meta Translate: SHIRAKATA Kentaro Status: in progress =end meta