File::Find::find() is depth-first?

Discussion in 'Perl Misc' started by gargoyle, Jan 10, 2005.

  1. gargoyle

    gargoyle Guest

    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.
     
    gargoyle, Jan 10, 2005
    #1
    1. Advertising

  2. gargoyle

    brian d foy Guest

    In article <BAjEd.4807$>, gargoyle
    <> 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,
    Subscribe to The Perl Review: http://www.theperlreview.com
     
    brian d foy, Jan 10, 2005
    #2
    1. Advertising

  3. gargoyle

    gargoyle Guest

    On 2005-01-10, brian d foy <> 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!
     
    gargoyle, Jan 10, 2005
    #3
  4. On Mon, 10 Jan 2005 00:00:33 GMT, gargoyle <> 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,
     
    Michele Dondi, Jan 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    421
  2. howa
    Replies:
    1
    Views:
    3,537
    mlimber
    Oct 26, 2006
  3. jono

    depth-first search of a tree

    jono, Oct 1, 2008, in forum: Python
    Replies:
    0
    Views:
    631
  4. Mark
    Replies:
    2
    Views:
    183
  5. depth first search

    , Apr 28, 2013, in forum: Java
    Replies:
    12
    Views:
    446
    Barb Knox
    May 2, 2013
Loading...

Share This Page