.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Wanted 3pm" .TH Wanted 3pm "2021-01-05" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" File::Find::Wanted \- More obvious wrapper around File::Find .SH "VERSION" .IX Header "VERSION" Version 1.00 .SH "SYNOPSIS" .IX Header "SYNOPSIS" File::Find is a great module, except that it doesn't actually find anything. Its \f(CW\*(C`find()\*(C'\fR function walks a directory tree and calls a callback function. Unfortunately, the callback function is deceptively called \f(CW\*(C`wanted\*(C'\fR, which implies that it should return a boolean saying whether you want the file. That's not how it works. .PP Most of the time you call \f(CW\*(C`find()\*(C'\fR, you just want to build a list of files. There are other modules that do this for you, most notably Richard Clamp's great File::Find::Rule, but in many cases, it's overkill, and you need to learn a new syntax. .PP With the \f(CW\*(C`find_wanted\*(C'\fR function, you supply a callback sub and a list of starting directories, but the sub actually should return a boolean saying whether you want the file in your list or not. .PP To get a list of all files ending in \fI.jpg\fR: .PP .Vb 1 \& my @files = find_wanted( sub { \-f && /\e.jpg$/ }, $dir ); .Ve .PP For a list of all directories that are not \fI\s-1CVS\s0\fR or \fI.svn\fR: .PP .Vb 1 \& my @files = find_wanted( sub { \-d && !/^(CVS|\e.svn)$/ }, $dir ) ); .Ve .PP It's easy, direct, and simple. .SH "WHY DO THIS?" .IX Header "WHY DO THIS?" The cynical may say \*(L"that's just the same as doing this\*(R": .PP .Vb 2 \& my @files; \& find( sub { push @files, $File::Find::name if \-f && /\e.jpg$/ }, $dir ); .Ve .PP Sure it is, but File::Find::Wanted makes it more obvious, and saves a line of code. That's worth it to me. I'd like it if \fBfind_wanted()\fR made its way into the File::Find distro, but for now, this will do. .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "find_wanted( \fI&wanted\fP, \fI\fP\f(CI@directories\fP\fI\fP )" .IX Subsection "find_wanted( &wanted, @directories )" Descends through \fI\f(CI@directories\fI\fR, calling the \fIwanted\fR function as it finds each file. The function returns a list of all the files and directories for which the \fIwanted\fR function returned a true value. .PP This is just a wrapper around \f(CW\*(C`File::Find::find()\*(C'\fR. See File::Find for details on how to modify its behavior. .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2005\-2012 Andy Lester. .PP This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License v2.0.