File::Zglob(3pm)

✨ File::Zglob β€” Extended globs πŸ’…

okay bestie, buckle up, because this is a Perl module and it is lowkey iconic. it lives in the User Contributed Perl Documentation section of your friendly neighbourhood man pages, and it is about to make your file matching so much cuter. πŸŽ€


🌸 NAME 🌸

File::Zglob β€” Extended globs. that's it. that's the name. she's simple, she's powerful, she's that girl. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

the whole vibe in four lines, no cap:

use File::Zglob;

my @files = zglob('**/*.{pm,pl}');

like. look at her. matching nested dirs AND multiple extensions in one little string. we love to see it. πŸ’–


πŸ’œ DESCRIPTION πŸ’œ

WARNINGS: THIS IS ALPHA VERSION. API MAY CHANGE WITHOUT NOTICE

okay first things first, bestie β€” this is ALPHA. the API can change without telling anybody. no heads-up, no text, nothing. so don't build your whole empire on it and then act surprised, iykyk. 😭

so what does she actually do? she provides the classic traditional Unix glob(3) functionality β€” you hand her a pattern, she hands you back a list of pathnames that match it. that's the whole deal. 🫢

but here's the glow-up: File::Zglob provides extended glob. she supports the "**/*.pm" form. so recursive matching? yes ma'am. πŸ‘‘


πŸŽ€ FUNCTIONS πŸŽ€

πŸ’… zglob($pattern) # => list of matched files

my @files = zglob('**/*.[ch]');

give her a pattern, get a list of matched files. that's the contract. πŸ’–

and here's a lil detail that matters a LOT, so listen up: unlike shell's glob, if there's no matching pathnames, () is returned. no error, no undef, no drama β€” just an empty list. she's emotionally mature like that. 🌈


⭐ Special chars ⭐

a glob pattern is made up of components and separator characters. and inside a component, these characters have main character energy β€” they mean something special. let's go one by one, bestie. 🧚

  • "*" β€” when it shows up at the beginning of a component, it matches zero or more characters except a period (.). and it will not match if the component of the input string begins with a period. otherwise (not at the start), it matches zero or more sequence of any characters. periodt. πŸ’…
  • "**" β€” if a component is just **, it matches zero or more number of components that match *. for example, src/**/*.h matches all of these patterns:
src/*.h
src/*/*.h
src/*/*/*.h
src/*/*/*/*.h
...

she's eating. every. single. time. πŸ”₯

  • "?" β€” at the beginning of a component, it matches a character except a period (.). otherwise, it matches any single character. one char, no more, no less. 🎯
  • "[chars]" β€” specifies a character set. matches any one of the set. the syntax of chars is the same as perl's character set syntax. so if you already know perl's sets, you already know this. slay. ✨
  • "{pm,pl}" β€” there is alternation. so "example.{foo,bar,baz}" matches "example.foo", "example.bar", and "example.baz". three for the price of one, we're obsessed. 😌

πŸŒ€ zglob and deep recursion πŸŒ€

okay this one's important so pay attention:

the "**/*" form makes deep recursion by soft link. and if it's deep recursion, zglob throw exception. so yeah β€” soft links plus ** can spiral, and she will not be quiet about it. she throws. consider yourself warned. πŸ’€


🌈 PORTABILITY 🌈

  • Win32 β€” Zglob supports Win32. πŸͺŸ zglob() only uses '/' as a path separator. and since zglob() accepts non-utf8 strings β€” CP932 contains '\' character as a second byte of multibyte chars. so yeah, that's a whole thing. the /-only rule is doing a lot of heavy lifting here. 🫢

πŸ™ˆ LIMITATIONS πŸ™ˆ

  • File order is not compatible with shells.

that's it. that's the limitation. the order of files she gives you won't line up with what your shell would do. don't compare them and get in your feelings about it. 😭


πŸ‘‘ AUTHOR πŸ‘‘

Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM> β€” the icon who made this happen. bow down. πŸ’œ


πŸ“ THANKS TO πŸ“

  • Most code was translated from gauche's fileutil.scm.
  • glob_to_regex function is taken from Text::Glob.

standing on the shoulders of legends, we love to see it. 🫢


🌟 SEE ALSO 🌟

File::DosGlob, Text::Glob, gauche's fileutil.scm β€” go read these next, bestie, they're the extended universe. πŸ“šβœ¨


πŸ’– LICENSE πŸ’–

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

free as in freedom, bestie. go wild (respectfully). 🌈


and that's the whole page, babes β€” this doc ships with perl v5.32.0 and was dated 2020-12-29, so shoutout to that era of the man pages. πŸ’…βœ¨

πŸ“¦ where this page comes from