.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.48) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "File::Listing 3" .TH File::Listing 3 2026-10-25 "perl v5.44.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 7 \& use File::Listing qw(parse_dir); \& $ENV{LANG} = "C"; # dates in non\-English locales not supported \& foreach my $file (parse_dir(\`ls \-l\`)) { \& my ($name, $type, $size, $mtime, $mode) = @$file; \& next if $type ne \*(Aqf\*(Aq; # plain file \& #... \& } \& \& # directory listing can also be read from a file \& open my $listing, "zcat ls\-lR.gz|"; \& $dir = parse_dir($listing, \*(Aq+0000\*(Aq); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module exports a single function called \f(CW\*(C`parse_dir\*(C'\fR, which can be used to parse directory listings. .SH FUNCTIONS .IX Header "FUNCTIONS" .SS parse_dir .IX Subsection "parse_dir" .Vb 8 \& my $dir = parse_dir( $listing ); \& my $dir = parse_dir( $listing, $time_zone ); \& my $dir = parse_dir( $listing, $time_zone, $type ); \& my $dir = parse_dir( $listing, $time_zone, $type, $error ); \& my @files = parse_dir( $listing ); \& my @files = parse_dir( $listing, $time_zone ); \& my @files = parse_dir( $listing, $time_zone, $type ); \& my @files = parse_dir( $listing, $time_zone, $type, $error ); .Ve .PP The first parameter (\f(CW$listing\fR) 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. .PP The second parameter (\f(CW$time_zone\fR) 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. .PP The third parameter (\f(CW$type\fR) is the type of listing to assume. Currently supported formats are \f(CW\*(Aqunix\*(Aq\fR, \f(CW\*(Aqapache\*(Aq\fR and \&\f(CW\*(Aqdosftp\*(Aq\fR. The default value is \f(CW\*(Aqunix\*(Aq\fR. Ideally, the listing type should be determined automatically. .PP The fourth parameter (\f(CW$error\fR) specifies how unparseable lines should be treated. Values can be \f(CW\*(Aqignore\*(Aq\fR, \f(CW\*(Aqwarn\*(Aq\fR or a code reference. Warn means that the perl \fBwarn()\fR 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 \&\f(CW\*(Aqignore\*(Aq\fR. .PP Only the first parameter is mandatory. .PP .Vb 4 \& # list context \& foreach my $file (parse_dir($listing)) { \& my($name, $type, $size, $mtime, $mode) = @$file; \& } \& \& # scalar context \& my $dir = parse_dir($listing); \& foreach my $file (@$dir) { \& my($name, $type, $size, $mtime, $mode) = @$file; \& } .Ve .PP The return value from \fBparse_dir()\fR 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: .IP name 4 .IX Item "name" The name of the file. .IP type 4 .IX Item "type" One of: \f(CW\*(C`f\*(C'\fR file, \f(CW\*(C`d\*(C'\fR directory, \f(CW\*(C`l\*(C'\fR symlink, \f(CW\*(C`?\*(C'\fR unknown. .IP size 4 .IX Item "size" The size of the file. .IP time 4 .IX Item "time" The number of seconds since January 1, 1970. .IP mode 4 .IX Item "mode" Bitmask a la the mode returned by \f(CW\*(C`stat\*(C'\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP File::Listing::Ftpcopy 4 .IX Item "File::Listing::Ftpcopy" Provides the same interface but uses XS and the parser implementation from \f(CW\*(C`ftpcopy\*(C'\fR.