man-pages/man3/File::Listing.3pm.html
2021-03-31 01:06:50 +01:00

114 lines
3.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of File::Listing</TITLE>
</HEAD><BODY>
<H1>File::Listing</H1>
Section: User Contributed Perl Documentation (3pm)<BR>Updated: 2012-02-15<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
File::Listing - parse directory listing
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
use File::Listing qw(parse_dir);
$ENV{LANG} = &quot;C&quot;; # dates in non-English locales not supported
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, &quot;zcat ls-lR.gz|&quot;);
$dir = parse_dir(\*LISTING, '+0000');
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This module exports a single function called <I>parse_dir()</I>, which can be
used to parse directory listings.
<P>
The first parameter to <I>parse_dir()</I> 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.
<P>
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.
<P>
The third parameter is the type of listing to assume. Currently
supported formats are 'unix', 'apache' and 'dosftp'. The default
value is 'unix'. Ideally, the listing type should be determined
automatically.
<P>
The fourth parameter specifies how unparseable lines should be treated.
Values can be 'ignore', 'warn' or a code reference. Warn means that
the perl <I>warn()</I> 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'.
<P>
Only the first parameter is mandatory.
<P>
The return value from <I>parse_dir()</I> 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 [
<TT>$filename</TT>, <TT>$filetype</TT>, <TT>$filesize</TT>, <TT>$filetime</TT>, <TT>$filemode</TT> ]. The
<TT>$filetype</TT> value is one of the letters 'f', 'd', 'l' or '?'. The
<TT>$filetime</TT> value is the seconds since Jan 1, 1970. The
<TT>$filemode</TT> is a bitmask like the mode returned by <I>stat()</I>.
<A NAME="lbAE">&nbsp;</A>
<H2>COPYRIGHT</H2>
Copyright 1996-2010, Gisle Aas
<P>
Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and
Net::FTP's parse_dir (Graham Barr).
<P>
This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">COPYRIGHT</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:43 GMT, March 31, 2021
</BODY>
</HTML>