Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   File::Find::find() is depth-first? (http://www.velocityreviews.com/forums/t890082-file-find-find-is-depth-first.html)

gargoyle 01-10-2005 12:00 AM

File::Find::find() is depth-first?
 
The File::Find man page says, under DESCRIPTION:

"find()" does a depth-first search over the given
@directories in the order they are given.

What exactly does depth-first mean here? I'm asking because to me it
signifies that filesystem children objects will come before their
parent. But the opposite happens in Perl 5.8.4, both on OpenBSD 3.6,
and the ActiveState 5.8.4 build 810. Well that's the behavior I get out
of this script anyway:

#!/usr/bin/perl -w

use File::Find;

@dirs = @ARGV;
find({ wanted => \&wanted, follow => 0, no_chdir => 1 }, @dirs);

sub wanted {
print "$_\t$File::Find::name\n";
}

Also, I checked an old Debian(3.0) Linux box sitting around here (with
Perl 5.6.1 installed) and its man page doesn't mention find() as being
depth-first.

brian d foy 01-10-2005 02:19 AM

Re: File::Find::find() is depth-first?
 
In article <BAjEd.4807$vM4.141@bignews3.bellsouth.net>, gargoyle
<gargoyle@no.spam> wrote:

> The File::Find man page says, under DESCRIPTION:
>
> "find()" does a depth-first search over the given
> @directories in the order they are given.
>
> What exactly does depth-first mean here? I'm asking because to me it
> signifies that filesystem children objects will come before their
> parent.


"Depth first" has the usual meaning:

http://en.wikipedia.org/wiki/Depth-first_search

Are you thinking about finddepth(), which invokes the callback
on the directory after it has already processed the children?

--
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com

gargoyle 01-10-2005 04:12 AM

Re: File::Find::find() is depth-first?
 
On 2005-01-10, brian d foy <comdog@panix.com> wrote:
> http://en.wikipedia.org/wiki/Depth-first_search
>
> Are you thinking about finddepth(), which invokes the callback
> on the directory after it has already processed the children?


Ahh that explains it! It's depth-first as opposed to breadth-first.

I was mainly concerned that find() would return parent nodes first,
because the code I'm working on now depends on that behavior. But
either of those algorithms would work fine.

Thanks for clearing that up!

Michele Dondi 01-10-2005 02:34 PM

Re: File::Find::find() is depth-first?
 
On Mon, 10 Jan 2005 00:00:33 GMT, gargoyle <gargoyle@no.spam> wrote:

>#!/usr/bin/perl -w


As side notes: better

use warnings;

nowadays. Also,

use strict;

always!

>use File::Find;
>
>@dirs = @ARGV;
>find({ wanted => \&wanted, follow => 0, no_chdir => 1 }, @dirs);


Why not

find({ wanted => \&wanted, follow => 0, no_chdir => 1 }, @ARGV);

incidentally?


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


All times are GMT. The time now is 12:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.