home *** CD-ROM | disk | FTP | other *** search
-
- <HTML>
- <HEAD>
- <TITLE>File::Recurse - Recurse over files, performing some function.</TITLE>
- <LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
- <LINK REV="made" HREF="mailto:">
- </HEAD>
-
- <BODY>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> File::Recurse - Recurse over files, performing some function.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- <A NAME="__index__"></A>
- <!-- INDEX BEGIN -->
-
- <UL>
-
- <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
-
- <LI><A HREF="#synopsis">SYNOPSIS</A></LI>
- <LI><A HREF="#description">DESCRIPTION</A></LI>
- <UL>
-
- <LI><A HREF="#context">Context</A></LI>
- <LI><A HREF="#controling recursion">Controling Recursion</A></LI>
- </UL>
-
- <LI><A HREF="#see also">SEE ALSO</A></LI>
- <LI><A HREF="#author">AUTHOR</A></LI>
- </UL>
- <!-- INDEX END -->
-
- <HR>
- <P>
- <H1><A NAME="name">NAME</A></H1>
- <P>File::Recurse - Recurse over files, performing some function.</P>
- <P>
- <HR>
- <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
- <UL>
- <LI>Linux</LI>
- <LI>Solaris</LI>
- <LI>Windows</LI>
- </UL>
- <HR>
- <H1><A NAME="synopsis">SYNOPSIS</A></H1>
- <PRE>
- use File::Recurse;
- use File::Copy;</PRE>
- <PRE>
- recurse { print } "/tmp";
- recurse {copy($_,"elsewhere") if -f $_} "dir";
- recurse(\&func, "/");</PRE>
- <P>
- <HR>
- <H1><A NAME="description">DESCRIPTION</A></H1>
- <P>The <CODE>File::Recurse</CODE> module is designed for performing an operation
- on a tree of directories and files. The basic usage is simmilar
- to the <EM>find.pl</EM> library. Once one uses the File::Recurse module,
- you need only call the <CODE>recurse</CODE> function in order to perform
- recursive directory operations.</P>
- <P>The function takes two parameters a function reference and a
- directory. The function referenced by the first parameter
- should expect to take one
- parameter: the full path to the file currently being operated on. This
- function is called once for every file and directory under the
- directory named by the second parameter.</P>
- <P>For example:</P>
- <PRE>
- recurse(\&func, "/");</PRE>
- <P>would start at the top level of the filesystem and call ``func''
- for every file and directory found (not including ``/'').</P>
- <P>Perl allows a second form of calling this function which can be
- useful for situations where you want to do something simple in
- the function. In these cases, you can define an anonymous function
- by using braces like so:</P>
- <PRE>
- recurse {print $_[0]} "/";</PRE>
- <P>This would print every file and directory in the filesystem. However,
- as an added convenience you can access the pathname in the variable
- <CODE>$_</CODE>. So the above could be rewritten as:</P>
- <PRE>
- recurse { print } "/";</PRE>
- <P>
- <H2><A NAME="context">Context</A></H2>
- <P>There is an optional third parameter which can be any scalar value
- (including a reference). This value is ignored by recurse, but will be
- passed as the second parameter to the user-defined function. This can
- be useful for building library routines that use recurse, so that
- they do not have to pass state to the function as global variables.</P>
- <P>
- <H2><A NAME="controling recursion">Controling Recursion</A></H2>
- <P>If you want to control how recursion happens, you have several
- options. First, there are some global variables that affect the overall
- operation of the recurse routine:</P>
- <DL>
- <DT><STRONG><A NAME="item_%24MAX_DEPTH"><CODE>$MAX_DEPTH</CODE></A></STRONG><BR>
- <DD>
- This variable controls how far down a tree of directories recurse
- will go before it assumes that something bad has happened. Default:
- 100.
- <P></P>
- <DT><STRONG><A NAME="item_%24FOLLOW_SYMLINKS"><CODE>$FOLLOW_SYMLINKS</CODE></A></STRONG><BR>
- <DD>
- This variable tells recurse if it should descend into directories that are
- symbolic links. Default: 0.
- <P></P></DL>
- <P>Normally, the return value of the function called is not used, but
- if it is -1 or -2, there is a special action taken.</P>
- <P>If the function returns -1 and the current filename refers to a
- directory, recurse will <STRONG>not</STRONG> descend into that directory. This
- can be used to prune searches and focus only on those directories
- which should be followed.</P>
- <P>If the function returns -2, the search is terminated, and recurse
- will return. This can be used to bail when a problem occurs, and you
- don't want to exit the program, or to end the search for some
- file once it is found.</P>
- <P>
- <HR>
- <H1><A NAME="see also">SEE ALSO</A></H1>
- <P><A HREF="../../../site/lib/File/Tools.html">the File::Tools manpage</A></P>
- <P>
- <HR>
- <H1><A NAME="author">AUTHOR</A></H1>
- <P>Written in 1996 by Aaron Sherman, <A HREF="mailto:ajs@ajs.com">ajs@ajs.com</A></P>
- <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
- <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
- <STRONG><P CLASS=block> File::Recurse - Recurse over files, performing some function.</P></STRONG>
- </TD></TR>
- </TABLE>
-
- </BODY>
-
- </HTML>
-