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 for (parse_dir(`ls -l`)) {
11 ($name, $type, $size, $mtime, $mode) = @$_;
12 next if $type ne 'f'; # plain file
13 #...
14 }
15
16 # directory listing can also be read from a file
17 open(LISTING, "zcat ls-lR.gz⎪");
18 $dir = parse_dir(\*LISTING, '+0000');
19
21 This module exports a single function called parse_dir(), which can be
22 used to parse directory listings. Currently it only understand Unix 'ls
23 -l' and 'ls -lR' format. It should eventually be able to most things
24 you might get back from a ftp server file listing (LIST command), i.e.
25 VMS listings, NT listings, DOS listings,...
26
27 The first parameter to parse_dir() is the directory listing to parse.
28 It can be a scalar, a reference to an array of directory lines or a
29 glob representing a filehandle to read the directory listing from.
30
31 The second parameter is the time zone to use when parsing time stamps
32 in the listing. If this value is undefined, then the local time zone is
33 assumed.
34
35 The third parameter is the type of listing to assume. The values will
36 be strings like 'unix', 'vms', 'dos'. Currently only 'unix' is imple‐
37 mented and this is also the default value. Ideally, the listing type
38 should be determined automatically.
39
40 The fourth parameter specifies how unparseable lines should be treated.
41 Values can be 'ignore', 'warn' or a code reference. Warn means that
42 the perl warn() function will be called. If a code reference is
43 passed, then this routine will be called and the return value from it
44 will be incorporated in the listing. The default is 'ignore'.
45
46 Only the first parameter is mandatory.
47
48 The return value from parse_dir() is a list of directory entries. In a
49 scalar context the return value is a reference to the list. The direc‐
50 tory entries are represented by an array consisting of [ $filename,
51 $filetype, $filesize, $filetime, $filemode ]. The $filetype value is
52 one of the letters 'f', 'd', 'l' or '?'. The $filetime value is the
53 seconds since Jan 1, 1970. The $filemode is a bitmask like the mode
54 returned by stat().
55
57 Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and
58 Net::FTP's parse_dir (Graham Barr).
59
60
61
62perl v5.8.8 2004-04-06 File::Listing(3)