IO::All works too. Here's some tasty idioms taken from the doc page:<div><br></div><div><div> # Read all the files/directories in a directory:</div><div> $io = io('my/directory/'); # Create new directory object</div>
<div> @contents = $io−>all; # Get all contents of dir</div><div> @contents = @$io; # Directory as an array</div><div> @contents = values %$io; # Directory as a hash</div>
<div> push @contents, $subdir # One at a time</div><div> while $subdir = $io−>next;</div><div><br></div><div> # Print the name and file type for all the contents above:</div>
<div> print "$_ is a " . $_−>type . "\n" # Each element of @contents</div><div> for @contents; # is an IO::All object!!</div><div><br></div>
<div> # Print first line of each file:</div><div> print $_−>getline # getline gets one line</div><div> for io('dir')−>all_files; # Files only</div>
<div><br></div><div> # Print names of all files/dirs three directories deep:</div><div> print "$_\n" for $io−>all(3); # Pass in the depth. Default=1</div><div><br></div><div>
# Print names of all files/dirs recursively:</div><div> print "$_\n" for $io−>all(0); # Zero means all the way down</div><div> print "$_\n" for $io−>All; # Capitalized shortcut</div>
<div> print "$_\n" for $io−>deep−>all; # Another way</div><div><br></div><br><div class="gmail_quote">2010/2/18 Tom Keller <span dir="ltr"><<a href="mailto:kellert@ohsu.edu">kellert@ohsu.edu</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div style="word-wrap:break-word">Summary for modules to traverse a directory tree: <div>0. q(don't roll your own. ... I know that, just needed the exercise.)</div>
<div>1. File::Next</div><div>2. File::Fu</div><div>3. File::Find::Object</div><div>4. File::Finder</div><div>5. File::Find</div><div><br></div><div>thanks,<br><div>
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Verdana;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Verdana;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Verdana;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Verdana;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Verdana;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="word-wrap:break-word">
<span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Verdana;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:Helvetica">
<span style="font-family:Helvetica">Tom</span></div><div style="font-family:Helvetica"><span style="font-family:Helvetica"><a href="mailto:kellert@ohsu.edu" target="_blank">kellert@ohsu.edu</a></span></div><div style="font-family:Helvetica">
<span style="font-family:Helvetica">503-494-2442</span></div></span></span></div></span></div></span><br></div></span><br></div></span><br></div></span><br></div></span><br></span><br>
</div>
<br><div><div>On Feb 18, 2010, at 11:40 AM, Eric Wilhelm wrote:</div><br><blockquote type="cite"><div># from Tom Keller<br># on Thursday 18 February 2010 11:04:<br><br><blockquote type="cite">I need to be able to process files within a directory tree.<br>
</blockquote><br>This will give you all of the files and directories under $topdir:<br><br> my @paths = File::Fu->dir($topdir)->find(sub{1});<br><br>If your matcher sub returns true, the file is returned. So for only the <br>
files:<br><br> my @files = File::Fu->dir($topdir)->find(sub{$_->is_file});<br><br>The filenames returned are File::Fu::File objects relative to wherever <br>$topdir is relative to (i.e. absolute if $topdir is absolute.)<br>
<br>If you want an iterator instead of one big list, you can use the <br>finder() method.<br><br> my $iter = File::Fu->dir($topdir)->finder(sub{1});<br><br> while(defined(my $path = $iter->())) {<br> $path or next;<br>
do_something_with($path);<br> }<br><br><a href="http://search.cpan.org/~ewilhelm/File-Fu-v0.0.6/lib/File/Fu/Dir.pm#finder" target="_blank">http://search.cpan.org/~ewilhelm/File-Fu-v0.0.6/lib/File/Fu/Dir.pm#finder</a><br>
<br>There is currently some better documentation for find(), finder(), and <br>the knob in my svn trunk:<br><br> <a href="http://svn.scratchcomputing.com/File-Fu/trunk/lib/File/Fu/Dir.pm" target="_blank">http://svn.scratchcomputing.com/File-Fu/trunk/lib/File/Fu/Dir.pm</a><br>
<br>--Eric<br>-- <br>Issues of control, repair, improvement, cost, or just plain<br>understandability all come down strongly in favor of open source<br>solutions to complex problems of any sort.<br>--Robert G. Brown<br>---------------------------------------------------<br>
<a href="http://scratchcomputing.com" target="_blank">http://scratchcomputing.com</a><br>---------------------------------------------------<br>_______________________________________________<br>Pdx-pm-list mailing list<br>
<a href="mailto:Pdx-pm-list@pm.org" target="_blank">Pdx-pm-list@pm.org</a><br><a href="http://mail.pm.org/mailman/listinfo/pdx-pm-list" target="_blank">http://mail.pm.org/mailman/listinfo/pdx-pm-list</a><br></div></blockquote>
</div><br></div></div><br>_______________________________________________<br>
Pdx-pm-list mailing list<br>
<a href="mailto:Pdx-pm-list@pm.org">Pdx-pm-list@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/pdx-pm-list" target="_blank">http://mail.pm.org/mailman/listinfo/pdx-pm-list</a><br></blockquote></div><br></div>