Commits

Shlomi Fish  committed c2bf3d7

Add the File::Find related items.

  • Participants
  • Parent commits 6f6e253

Comments (0)

Files changed (3)

     - an up-to-date one is really needed.
     - There is one at http://www.perlmonks.org/?node_id=879515 .
 
+* Bad elements page:
+    - Recursively iterating over directories and sub-directories instead of
+    using File::Find, F::F::O, File::Next, etc.
+    - Using File::Find and friends for listing the entries of a single
+    directory (non-recursively).
 * Add to '/bad-elements/':
     - Using one variable for two different things
         - assignment to a different value in the middle of the subroutine.
-    - Recursively iterating over directories and sub-directories instead of
-    using File::Find, F::F::O, File::Next, etc.
-    - Using File::Find and friends for listing the entries of a single
-    directory (non-recursively).
     - Populating an array of references with the same reference:
         - ([]) x $count
         - my @array;

File src/tutorials/bad-elements/index.html.wml

 
 </item>
 
+<item id="recursive_directory_traversal" h="Recursive Directory Traversal Without Using File::Find and Friends">
+
+<p>
+Some beginners to Perl are tempted to write a recursive directory traversal
+(i.e: finding all files in a directory, its sub-directories, its
+sub-sub-directories, etc.) by using procedural recursion or other sub-optimal
+means. However, the idiomatic way is to use the core module File::Find or
+its CPAN friends. For more information, see
+<a href="$(ROOT)/uses/sys-admin/#directory_traversal">our resources about
+directory traversal</a>.
+</p>
+
+</item>
+
+<item id="non_recursive_file_find" h="Using File::Find for listing the contents of a directory non-recursively">
+
+<p>
+Alternatively, sometimes people are tempted to use File::Find or similar
+modules to non-recursively list the contents of a single directory. However,
+in this case, it is a better idea to simply use
+<pdoc_f f="opendir">opendir()</pdoc_f>,
+<pdoc_f f="readdir">readdir()</pdoc_f> and
+<pdoc_f f="closedir">closedir()</pdoc_f>, in conjunction with
+<a href="#no_upwards_for_dirs">no_upwards</a>, or an abstraction of them.
+</p>
+
+<p>
+File::Find and friends should be reserved for a recursive traversal.
+</p>
+
+</item>
+
 </main_list>
 
 #include "bad-elements-sources.wml"