1File::Listing(3)      User Contributed Perl Documentation     File::Listing(3)
2
3
4

NAME

6       File::Listing - Parse directory listing
7

VERSION

9       version 6.14
10

SYNOPSIS

12        use File::Listing qw(parse_dir);
13        $ENV{LANG} = "C";  # dates in non-English locales not supported
14        foreach my $file (parse_dir(`ls -l`)) {
15            my ($name, $type, $size, $mtime, $mode) = @$file;
16            next if $type ne 'f'; # plain file
17            #...
18        }
19
20        # directory listing can also be read from a file
21        open my $listing, "zcat ls-lR.gz|";
22        $dir = parse_dir($listing, '+0000');
23

DESCRIPTION

25       This module exports a single function called "parse_dir", which can be
26       used to parse directory listings.
27

FUNCTIONS

29   parse_dir
30        my $dir = parse_dir( $listing );
31        my $dir = parse_dir( $listing, $time_zone );
32        my $dir = parse_dir( $listing, $time_zone, $type );
33        my $dir = parse_dir( $listing, $time_zone, $type, $error );
34        my @files = parse_dir( $listing );
35        my @files = parse_dir( $listing, $time_zone );
36        my @files = parse_dir( $listing, $time_zone, $type );
37        my @files = parse_dir( $listing, $time_zone, $type, $error );
38
39       The first parameter ($listing) is the directory listing to parse.  It
40       can be a scalar, a reference to an array of directory lines or a glob
41       representing a filehandle to read the directory listing from.
42
43       The second parameter ($time_zone) is the time zone to use when parsing
44       time stamps in the listing. If this value is undefined, then the local
45       time zone is assumed.
46
47       The third parameter ($type) is the type of listing to assume.
48       Currently supported formats are 'unix', 'apache' and 'dosftp'. The
49       default value is 'unix'. Ideally, the listing type should be determined
50       automatically.
51
52       The fourth parameter ($error) specifies how unparseable lines should be
53       treated. Values can be 'ignore', 'warn' or a code reference.  Warn
54       means that the perl warn() function will be called.  If a code
55       reference is passed, then this routine will be called and the return
56       value from it will be incorporated in the listing.  The default is
57       'ignore'.
58
59       Only the first parameter is mandatory.
60
61        # list context
62        foreach my $file (parse_dir($listing)) {
63            my($name, $type, $size, $mtime, $mode) = @$file;
64        }
65
66        # scalar context
67        my $dir = parse_dir($listing);
68        foreach my $file (@$dir) {
69            my($name, $type, $size, $mtime, $mode) = @$file;
70        }
71
72       The return value from parse_dir() is a list of directory entries.  In a
73       scalar context the return value is a reference to the list.  The
74       directory entries are represented by an array consisting of:
75
76       name
77           The name of the file.
78
79       type
80           One of: "f" file, "d" directory, "l" symlink, "?" unknown.
81
82       size
83           The size of the file.
84
85       time
86           The number of seconds since January 1, 1970.
87
88       mode
89           Bitmask a la the mode returned by "stat".
90

SEE ALSO

92       File::Listing::Ftpcopy
93           Provides the same interface but uses XS and the parser
94           implementation from "ftpcopy".
95

AUTHOR

97       Original author: Gisle Aas
98
99       Current maintainer: Graham Ollis <plicease@cpan.org>
100
101       Contributors:
102
103       Adam Kennedy
104
105       Adam Sjogren
106
107       Alex Kapranoff
108
109       Alexey Tourbin
110
111       Andreas J. Koenig
112
113       Bill Mann
114
115       Bron Gondwana
116
117       DAVIDRW
118
119       Daniel Hedlund
120
121       David E. Wheeler
122
123       David Steinbrunner
124
125       Erik Esterer
126
127       FWILES
128
129       Father Chrysostomos
130
131       Gavin Peters
132
133       Graeme Thompson
134
135       Hans-H. Froehlich
136
137       Ian Kilgore
138
139       Jacob J
140
141       Mark Stosberg
142
143       Mike Schilli
144
145       Ondrej Hanak
146
147       Peter John Acklam
148
149       Peter Rabbitson
150
151       Robert Stone
152
153       Rolf Grossmann
154
155       Sean M. Burke
156
157       Simon Legner
158
159       Slaven Rezic
160
161       Spiros Denaxas
162
163       Steve Hay
164
165       Todd Lipcon
166
167       Tom Hukins
168
169       Tony Finch
170
171       Toru Yamaguchi
172
173       Ville Skyttä
174
175       Yuri Karaban
176
177       Zefram
178
179       amire80
180
181       jefflee
182
183       john9art
184
185       mschilli
186
187       murphy
188
189       phrstbrn
190
191       ruff
192
193       sasao
194
195       uid39246
196
198       This software is copyright (c) 1996-2020 by Gisle Aas.
199
200       This is free software; you can redistribute it and/or modify it under
201       the same terms as the Perl 5 programming language system itself.
202
203
204
205perl v5.32.1                      2021-01-27                  File::Listing(3)
Impressum