- glob EXPR
- glob
-
In list context, returns a (possibly empty) list of filename expansions on the value of EXPR such as the standard Unix shell /bin/csh would do. In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted. This is the internal function implementing the
<*.c>
operator, but you can use it directly. If EXPR is omitted,$_
is used. The<*.c>
operator is discussed in more detail in "I/O Operators" in perlop.リストコンテキストでは、 EXPR の値を、標準 Unix シェル /bin/csh が行なうように ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。 スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、 リストがなくなったら undef を返します。 これは、
<*.c>
演算子を実装する内部関数ですが、 直接使用することもできます。 EXPR が省略されると、$_
が使われます。<*.c>
演算子については "I/O Operators" in perlop でより詳細に議論しています。Note that
glob
splits its arguments on whitespace and treats each segment as separate pattern. As such,glob("*.c *.h")
matches all files with a .c or .h extension. The expressionglob(".* *")
matches all files in the current working directory. If you want to glob filenames that might contain whitespace, you'll have to use extra quotes around the spacey filename to protect it. For example, to glob filenames that have ane
followed by a space followed by anf
, use one of:glob
は引数を空白で分割して、それぞれを分割された パターンとして扱います。 従って、glob("*.c *.h")
は .c または .h 拡張子を持つ全てのファイルに マッチングします。 式glob(".* *")
はカレントワーキングディレクトリの全てのファイルに マッチングします。 空白を含んでいるかも知れないファイル名をグロブしたい場合、それを守るために 空白入りファイル名の周りに追加のクォートを使う必要があります。 例えば、e
の後に空白、その後にf
というファイル名をグロブするには 以下の一つを使います:my @spacies = <"*e f*">; my @spacies = glob '"*e f*"'; my @spacies = glob q("*e f*");
If you had to get a variable through, you could do this:
変数を通す必要があった場合、以下のようにできました:
my @spacies = glob "'*${var}e f*'"; my @spacies = glob qq("*${var}e f*");
If non-empty braces are the only wildcard characters used in the
glob
, no filenames are matched, but potentially many strings are returned. For example, this produces nine strings, one for each pairing of fruits and colors:空でない中かっこが
glob
で使われている唯一の ワイルドカード文字列の場合、ファイル名とはマッチングせず、 可能性のある文字列が返されます。 例えば、これは 9 個の文字列を生成し、それぞれは果物と色の組み合わせに なります:my @many = glob "{apple,tomato,cherry}={green,yellow,red}";
This operator is implemented using the standard
File::Glob
extension. See File::Glob for details, includingbsd_glob
, which does not treat whitespace as a pattern separator.v5.6.0 から、この演算子は標準の
File::Glob
拡張を使って 実装されています。 空白をパターンのセパレータとして扱わないbsd_glob
を含めた 詳細は File::Glob を参照してください。Portability issues: "glob" in perlport.
移植性の問題: "glob" in perlport。