1File::Listing(3) User Contributed Perl Documentation File::Listing(3)
2
3
4
6 File::Listing - parse directory listing
7
9 use File::Listing qw(parse_dir);
10 $ENV{LANG} = "C"; # dates in non-English locales not supported
11 for (parse_dir(`ls -l`)) {
12 ($name, $type, $size, $mtime, $mode) = @$_;
13 next if $type ne 'f'; # plain file
14 #...
15 }
16
17 # directory listing can also be read from a file
18 open(LISTING, "zcat ls-lR.gz|");
19 $dir = parse_dir(\*LISTING, '+0000');
20
22 This module exports a single function called parse_dir(), which can be
23 used to parse directory listings.
24
25 The first parameter to parse_dir() is the directory listing to parse.
26 It can be a scalar, a reference to an array of directory lines or a
27 glob representing a filehandle to read the directory listing from.
28
29 The second parameter is the time zone to use when parsing time stamps
30 in the listing. If this value is undefined, then the local time zone is
31 assumed.
32
33 The third parameter is the type of listing to assume. Currently
34 supported formats are 'unix', 'apache' and 'dosftp'. The default value
35 'unix'. Ideally, the listing type should be determined automatically.
36
37 The fourth parameter specifies how unparseable lines should be treated.
38 Values can be 'ignore', 'warn' or a code reference. Warn means that
39 the perl warn() function will be called. If a code reference is
40 passed, then this routine will be called and the return value from it
41 will be incorporated in the listing. The default is 'ignore'.
42
43 Only the first parameter is mandatory.
44
45 The return value from parse_dir() is a list of directory entries. In a
46 scalar context the return value is a reference to the list. The
47 directory entries are represented by an array consisting of [
48 $filename, $filetype, $filesize, $filetime, $filemode ]. The $filetype
49 value is one of the letters 'f', 'd', 'l' or '?'. The $filetime value
50 is the seconds since Jan 1, 1970. The $filemode is a bitmask like the
51 mode returned by stat().
52
54 Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and
55 Net::FTP's parse_dir (Graham Barr).
56
57
58
59perl v5.12.4 2010-09-20 File::Listing(3)