Commits

Shlomi Fish committed 357d51c

Add more.

Comments (0)

Files changed (3)

                     title => "Debugging Perl Programs",
                 },
                 {
+                    text => "Files and Directories",
+                    url => "topics/files-and-directories/",
+                    title => "Handling Files and Directories in Perl",
+                },
+                {
                     text => "Hashes",
                     url => "topics/hashes/",
                     title => "Hashes / Associative Arrays for Mapping Keys to Values",

src/topics/files-and-directories/index.html.wml

+#include '../template.wml'
+
+<latemp_subject "Files and Directories Handling in Perl" />
+
+<p>
+Perl has strong support for handling files and directories, which are the
+bread-and-butter of dealing with the disk and the filesystem. Many modules
+on <a href="$(ROOT)/cpan/">CPAN (= the Comprehensive Perl Archive Network)</a>
+aim to facilitate the task even further.
+</p>
+
+<h2 id="basics">The Basics</h2>
+
+<p>
+For the basics, read about the open function (on 
+<pdoc d="perlopentut"></pdoc> or 
+on <a href="$(ROOT)/resources/">recommended books or tutorials</a>) as well as 
+other built-ins such as
+<pdoc_f f="opendir">opendir</pdoc_f>, <pdoc_f f="readdir">readdir</pdoc_f>,
+<pdoc_f f="closedir">closedir</pdoc_f>, <pdoc_f f="mkdir">mkdir</pdoc_f>. There
+are also many UNIX-oriented file-system-builtins listed on <pdoc d="perlfunc"></pdoc> which may prove of utility.
+</p>
+
+<h2 id="modules">Modules</h2>
+
+<p>
+Useful modules for files and directories handling are:
+</p>
+
+<ul>
+
+<li>
+<a href="http://perldoc.perl.org/File/Spec.html">File::Spec</a> - a core module
+to handle file and directory paths portably.
+</li>
+
+<li>
+<cpan_self_dist d="String-ShellQuote" />
+- quote strings for passing through the shell. Also see the list forms of
+system.
+</li>
+
+<li>
+<cpan_self_mod m="File::Path" /> - a core module to create or remove directory 
+trees (portably).
+</li>
+
+<li>
+<cpan_self_mod m="File::Copy" /> - a core module to copy files.
+</li>
+
+<li>
+<cpan_self_dist d="IO-All" /> - an all-in-one
+IO package with a lot of syntactic sugar. Non-core.
+</li>
+
+</ul>
+
+<h3 id="directory_traversal">Directory Traversal</h3>
+
+<p>
+The built-in module for traversing a directory tree in Perl is 
+<cpan_self_mod m="File::Find" />, but it has some severe limitations in interface
+and use. Some better alternatives are:
+</p>
+
+<ul>
+
+<li>
+<p>
+<a href="http://www.shlomifish.org/open-source/projects/File-Find-Object/">File-Find-Object</a> - an object-oriented replacement for File::Find that:
+1) can be instantiated 2) has an iterative interface 3) can be interrupted in
+the middle and 4) can return result objects instead of path names.
+</p>
+</li>
+
+<li>
+<p>
+<cpan_self_dist d="File-Next" /> - an alternative with an iterative interface,
+but incapable of being instantiated.
+</p>
+</li>
+
+<li>
+<p>
+<cpan_self_dist d="File-Find-Rule" />, which is still based on File::Find, and
+<cpan_self_dist d="File-Find-Object-Rule" /> provide a more convenient and 
+succinct interface for finding what you want.
+</p>
+</li>
+
+</ul>

src/topics/index.html.wml

 one. This page gives some resources for learning about hashes. 
 </p>
 
+<h3 id="files-and-dirs"><a href="files-and-directories/">Files and Directories Handling</a></h3>
+
+<p>
+How to handle files and directories in Perl.
+</p>
+
 <h3 id="references"><a href="references/">References</a></h3>
 
 <p>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.