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 perl warn() 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 by stat. 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

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