libwww-perl-5.813 > File::Listing
libwww-perl-5.813
Other versions:
libwww-perl-5.836

名前

File::Listing - parse directory listing

File::Listing - ディレクトリ一覧をパースする

概要

 use File::Listing qw(parse_dir);
 for (parse_dir(`ls -l`)) {
     ($name, $type, $size, $mtime, $mode) = @$_;
     next if $type ne 'f'; # plain file
     #...
 }

 # directory listing can also be read from a file
 open(LISTING, "zcat ls-lR.gz|");
 $dir = parse_dir(\*LISTING, '+0000');

説明

This module exports a single function called parse_dir(), which can be used to parse directory listings. Currently it only understand Unix 'ls -l' and 'ls -lR' format. It should eventually be able to most things you might get back from a ftp server file listing (LIST command), i.e. VMS listings, NT listings, DOS listings,...

このモジュールは parse_dir() という一つだけの関数をエクスポートしていて、 これはディレクトリツリーのパースに使えます。 今のところ Unix の 'ls -l''ls -lR' の形式にのみ対応しています。 最終的には ftp サーバから返されるかもしれない ファイルリスト (LIST コマンド) に対応する予定です; VMS リスト、NT リスト, DOS リストなど…

The first parameter to parse_dir() is the directory listing to parse. It can be a scalar, a reference to an array of directory lines or a glob representing a filehandle to read the directory listing from.

parse_dir() の 1 番目の引数はパースするディレクトリ一覧です。 これはスカラ、ディレクトリ行の配列へのリファレンス、ディレクトリ一覧を 読み込むファイルハンドルを表現したグロブ、のいずれかです。

The second parameter is the time zone to use when parsing time stamps in the listing. If this value is undefined, then the local time zone is assumed.

2 番目の引数は一覧の時刻をパースするときに使うタイムゾーンです。 この値が未定義の場合、ローカルのタイムゾーンが仮定されます。

The third parameter is the type of listing to assume. The values will be strings like 'unix', 'vms', 'dos'. Currently only 'unix' is implemented and this is also the default value. Ideally, the listing type should be determined automatically.

3 番目の引数は仮定する一覧の種類です。 値は 'unix', 'vms', 'dos' といった文字列です。 現在の所 'unix' だけが実装されていて、これがデフォルト値です。 理想的には、一覧の種類は自動的に決定されるべきです。

The fourth parameter specifies how unparseable lines should be treated. Values can be 'ignore', 'warn' or a code reference. Warn means that the perl warn() function will be called. If a code reference is passed, then this routine will be called and the return value from it will be incorporated in the listing. The default is 'ignore'.

4 番目の引数は、パースできない行をどう扱うかを指定します。 値は 'ignore' か 'warn' かコードリファレンスです。 'warn' は、perl の warn() 関数が呼び出されます。 コードリファレンスが渡されると、指定されたルーチンが呼び出され、 その返り値が一覧に加えられます。 デフォルトは 'ignore' です。

Only the first parameter is mandatory.

最初のパラメータのみが必須です。

The return value from parse_dir() is a list of directory entries. In a scalar context the return value is a reference to the list. The directory entries are represented by an array consisting of [ $filename, $filetype, $filesize, $filetime, $filemode ]. The $filetype value is one of the letters 'f', 'd', 'l' or '?'. The $filetime value is the seconds since Jan 1, 1970. The $filemode is a bitmask like the mode returned by stat().

The return value from parse_dir() からの返り値は、ディレクトリエントリのリストです。 スカラコンテキストでは、リストへのリファレンスです。 ディレクトリエントリは [$filename, $filetype, $filesize, $filetime, $filemode ] で構成される配列で表現されます。 $filetype の値は 'f', 'd', 'l', '?' の文字のいずれかです。 $filetime の値は 1970 年 1 月 1 日からの秒数です。 $filemode は stat() で返されるモードのようなビットマスクです。

CREDITS

Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and Net::FTP's parse_dir (Graham Barr).

(Lee McLoughlin による ftp mirror パッケージの) lsparse.pl と、 (Graham Barr による) Net::FTP の parse_dir を基にしています。