File::Listing(3)
π File::Listing(3) π
okay bestie, welcome to the User Contributed Perl Documentation for File::Listing(3) β the manual page that's literally about parsing directory listings. it's giving βI read ls -l so you don't have toβ energy, and honestly? iconic. β¨
πΈ NAME πΈ
File::Listing β Parse directory listing.
π VERSION π
version 6.16, periodt. π
π¦ SYNOPSIS π¦
okay so here's the whole vibe in code form:
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 'f'; # plain file
#...
}
# directory listing can also be read from a file
open my $listing, "zcat ls-lR.gz|";
$dir = parse_dir($listing, '+0000');
heads up: dates in non-English locales are not supported β that's in the code comment, bestie, not me being dramatic. π
π§ DESCRIPTION π§
this module exports a single function called parse_dir, and its whole job is parsing directory listings. that's it. that's the module. π
β¨ FUNCTIONS β¨
π parse_dir π
here are the signatures, looking all official:
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 );
okay so the parameters, one by one:
$listingβ the directory listing you're parsing. 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. yes, it's flexible like that. π«Ά$time_zoneβ the time zone to use when parsing time stamps in the listing. if this value is undefined, then the local time zone is assumed. lowkey important. β°$typeβ 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. (we love an aspirational default. β¨)$errorβ specifies how unparseable lines should be treated. values can be'ignore','warn'or a code reference.'warn'means that the perlwarn()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'. no cap. π
Only the first parameter is mandatory. the rest are optional, like a little treat. π
here's list context:
# list context
foreach my $file (parse_dir($listing)) {
my($name, $type, $size, $mtime, $mode) = @$file;
}
and here's scalar context:
# scalar context
my $dir = parse_dir($listing);
foreach my $file (@$dir) {
my($name, $type, $size, $mtime, $mode) = @$file;
}
the return value from parse_dir() 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:
nameβ the name of the file. obviously. πtypeβ one of:"f"file,"d"directory,"l"symlink,"?"unknown. mystery box energy for"?". πsizeβ the size of the file.timeβ the number of seconds since January 1, 1970. the classic Unix epoch moment. π°οΈmodeβ bitmask a la the mode returned bystat. very demure, very bitmask. π
π SEE ALSO π
File::Listing::Ftpcopyβ provides the same interface but uses XS and the parser implementation from"ftpcopy". same vibe, different under-the-hood situation. π₯
π AUTHOR π
Original author: Gisle Aas π
Current maintainer: Graham Ollis <plicease@cpan.org> π«Ά
Contributors, aka the group chat:
- Adam Kennedy
- Adam Sjogren
- Alex Kapranoff
- Alexey Tourbin
- Andreas J. Koenig
- Bill Mann
- Bron Gondwana
- DAVIDRW
- Daniel Hedlund
- David E. Wheeler
- David Steinbrunner
- Erik Esterer
- FWILES
- Father Chrysostomos
- Gavin Peters
- Graeme Thompson
- Grant Street Group
- Hans-H. Froehlich
- Ian Kilgore
- Jacob J
- Mark Stosberg
- Mike Schilli
- Ondrej Hanak
- Peter John Acklam
- Peter Rabbitson
- Robert Stone
- Rolf Grossmann
- Sean M. Burke
- Simon Legner
- Slaven Rezic
- Spiros Denaxas
- Steve Hay
- Todd Lipcon
- Tom Hukins
- Tony Finch
- Toru Yamaguchi
- Ville SkyttΓ€
- Yuri Karaban
- Zefram
- amire80
- jefflee
- john9art
- mschilli
- murphy
- phrstbrn
- ruff
- sasao
- uid39246
π COPYRIGHT AND LICENSE π
this software is copyright (c) 1996-2022 by Gisle Aas. π
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. slay, legally speaking. βοΈβ¨
okay bestie, that's the whole page π it's File::Listing(3) from perl v5.42.0, dated 2024-03-08 β go parse some directories, you absolute icon. π«ΆπΈ
π¦ where this page comes from
- opensuse-leap 16.0: perl-File-Listing 6.160.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms