FnMatch(3pm)
π FnMatch(3pm) β the vibe π
okay bestie, so this is the manual page for File::FnMatch, living in the Perl docs under "User Contributed Perl Documentation" (yes that's the man name up there, FnMatch(3pm)). It's giving lowercase-and-quiet, but it does a lot of heavy lifting for a tiny module. Sit down, we're matching filenames. π
β¨ NAME β¨
File::FnMatch β simple filename and pathname matching. That's it, that's the whole thesis. No cap.
π¦ SYNOPSIS π¦
Like, here's the whole thing in action:
use File::FnMatch qw(:fnmatch); # import everything
# shell-style: match "/a/bc", but not "/a/.bc" nor "/a/b/c"
fnmatch("/a/*", $fn, FNM_PATHNAME|FNM_PERIOD);
# find our A- executables only
grep { fnmatch("A-*.exe", $_) } readdir SOMEDIR;
The first one is your classic shell-style moment: it matches /a/bc but NOT /a/.bc and NOT /a/b/c. The second one is girlband energy β we're finding our A- executables only, one readdir at a time. π
πΈ DESCRIPTION πΈ
File::FnMatch::fnmatch() gives you simple, shell-like pattern matching. That's the whole product, and honestly? It ate.
She's considerably less powerful than regular expressions, periodt. But shell patterns are still useful and familiar to a huge audience of end-users, which lowkey is the entire point. Your users already know how * works. You do not have to teach them regex. Iconic.
π Functions π
fnmatch ( PATTERN, STRING [, FLAGS] )β returns true if PATTERN matches STRING, andundefotherwise. That's the bare minimum, bestie. FLAGS can be the bitwise OR'ing of any of the supportedFNM_*constants (peep the next section, they're right there π).
π§ Constants π§
FNM_NOESCAPEβ do NOT treat a backslash ('\') in PATTERN specially. Otherwise (i.e. normally), a backslash escapes whatever character comes next. Choose your fighter.FNM_PATHNAMEβ prohibits wildcards from matching a slash ('/'). Your wildcards cannot cross the path boundary, no matter how much they want to.FNM_PERIODβ prohibits wildcards from matching a period ('.') at the start of a string, and β ifFNM_PATHNAMEis also given β immediately after a slash. Dotfiles are protected, as they deserve to be. π«Ά
Other possibilities include at least FNM_CASEFOLD (compare "qr//i"), FNM_LEADING_DIR to restrict matching to everything before the first '/', FNM_FILE_NAME as a synonym for FNM_PATHNAME, and the rather more exotic FNM_EXTMATCH. Consult your system documentation for details β no fr fr, actually go read it, she's not guessing for you.
π EXPORT π
None by default. The export tag ":fnmatch" exports the fnmatch function and all available FNM_* constants. So when you want everything, you say qw(:fnmatch) and everything arrives. Main character tag behavior.
β PATTERN SYNTAX β
Okay so the wildcards are:
- the question mark (
'?'), matching any single character - the asterisk (
'*'), matching zero or more characters
FNM_PATHNAME and FNM_PERIOD restrict the scope of those wildcards β notably supporting the classic UNIX convention of concealing "dotfiles". π
Then we get to bracket expressions, enclosed by '[' and ']', which match any of a set of characters. You can specify them:
- explicitly β
"[abcdef]" - as a range β
"[a-f0-9]" - as the combination of these β
"[a-f0-9XYZ]"
Additionally, many implementations support named character classes such as "[[:xdigit:]]". And character sets may be negated with an initial '!', like "[![:space:]]". Negation?? She's got range, literally.
Also, important: locale influences the meaning of fnmatch() patterns. So your patterns are not living in a vacuum, she is a product of her environment. iykyk.
π CAVEATS π
Most UNIX-like systems provide an fnmatch implementation. This module will not work on platforms lacking an implementation β most notably Win32. So if you're on Win32 bestie, this is not your moment, and I'm so sorry. π₯²
π SEE ALSO π
File::GlobPOSIX::setlocalefnmatch(3)
π AUTHOR π
Michael J. Pomraning
Please report bugs to <mjp-perl AT pilcrow.madison.wi.us> β yes, that's the address, be normal about it.
π COPYRIGHT AND LICENSE π
Copyright 2005 by Michael J. Pomraning
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page, you're so welcome. π¦ this was documented as part of perl v5.42.3 and the doc itself is dated 2026-08-19 β so when you cite me, cite the vibe and the version, both. periodt. π β¨πΈ
π¦ where this page comes from
- ubuntu stonking: libfile-fnmatch-perl 0.02-3build6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms