- glob EXPR
 - glob
 - 
In list context, returns a (possibly empty) list of filename expansions on the value of EXPR such as the Unix shell Bash would do. In scalar context, glob iterates through such filename expansions, returning undef when the list is exhausted. If EXPR is omitted,
$_is used.リストコンテキストでは、 EXPR の値を、Unix シェルの Bash が行なうように ファイル名の展開を行なった結果のリスト(空かもしれません)を返します。 スカラコンテキストでは、glob はこのようなファイル名展開を繰り返し、 リストがなくなったら undef を返します。 EXPR が省略されると、
$_が使われます。# List context my @txt_files = glob("*.txt"); my @perl_files = glob("*.pl *.pm"); # Scalar context while (my $file = glob("*.mp3")) { # Do stuff }Glob also supports an alternate syntax using
<>as delimiters. While this syntax is supported, it is recommended that you useglobinstead as it is more readable and searchable.glob はまた区切り文字として
<>を使うもう一つの文法に 対応しています。 この文法は対応していますが、可読性と検索性がより高いので、代わりにglobを使うことを勧めます。my @txt_files = <"*.txt">;If you need case insensitive file globbing that can be achieved using the
:nocaseparameter of thebsd_globmodule.大文字小文字を区別するファイルグロブが必要な場合、
bsd_globモジュールの:nocase引数を 使うことで達成できます:use File::Glob qw(:globally :nocase); my @txt = glob("readme*"); # README readme.txt Readme.mdNote that
globsplits 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 anefollowed 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::Globextension. Seebsd_globfor details, includingbsd_glob, which does not treat whitespace as a pattern separator.この演算子は標準の
File::Glob拡張を使って 実装されています。 空白をパターンのセパレータとして扱わないbsd_globを含めた 詳細はbsd_globを参照してください。If a
globexpression is used as the condition of awhileorforloop, then it will be implicitly assigned to$_. If either aglobexpression or an explicit assignment of aglobexpression to a scalar is used as awhile/forcondition, then the condition actually tests for definedness of the expression's value, not for its regular truth value.glob式がwhileやforループの条件として使われた場合、 これは暗黙に$_に代入されます。glob式またはglob式からスカラへの明示的な代入がwhile/forの条件部として使われた場合、 条件は通常の真の値かどうかではなく、式の値が定義されているかどうかを テストします。Internal implementation details:
内部実装の詳細:
This is the internal function implementing the
<*.c>operator, but you can use it directly. The<*.c>operator is discussed in more detail in "I/O Operators" in perlop.これは、
<*.c>演算子を実装する内部関数ですが、 直接使用することもできます。<*.c>演算子については "I/O Operators" in perlop でより詳細に議論しています。Portability issues: "glob" in perlport.
移植性の問題: "glob" in perlport。