Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

by moritz (Cardinal)
on Jun 16, 2008 at 21:01 UTC ( #692369=note: print w/replies, xml ) Need Help??


in reply to Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

Turning that into an iterator sounds like an interesting task, but it's hard to do without having code that actually runs. So your best bet for getting a complete solution is to provide a complete script that constructs such a tree structure, runs the sub against it, and compares the output to the desired result, preferably using Test::More or something along these lines.

I will be offline for a few days, if nobody else answers in the meantime I'll do it ;-)

If you just want to return some results from a sub and then continue running that sub, you can take a look at Coro, which allows you to do just that (or, to advertise my own modules, Perl6::GatherTake, which is just a nice wrapper around some Coro functions).

  • Comment on Re: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?

Replies are listed 'Best First'.
Re^2: Eliminating Recursive Tree Walking by using MJD-style Infinite Streams?
by jryan (Vicar) on Jun 16, 2008 at 21:53 UTC
    Hmmm, thats fair. Give me a minute and I'll attach some code and some test files. Is there any easy way to attach a zip file here?

      Here is some code I wrote back in 2001 that takes advantage of the fact that we can push onto an array we are currently iterating over. So it's called an infinite stream eh, cute name. Anyway this happily recurses a directory (or any other) tree.

      my $root = 'c:/somedir/'; my @dirs = ($root); my @files; for my $path (@dirs){ opendir ( DIR, $path ) or next; # skip dirs we can't read while (my $file = readdir DIR) { next if $file eq '.' or $file eq '..';# skip dot files next if -l $path.$file; # skip sym links if ( -d $path.$file ) { push @dirs, $path.$file.'/'; # add dir to list } else { push @files, $path.$file; # add file to list } } closedir DIR; }
      Is there any easy way to attach a zip file here?

      No, you have to upload it somewhere else and link it here then.

      But first check if ikegami's solution works for you - if yes, no need to duplicate the effort.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://692369]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2021-12-03 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (29 votes). Check out past polls.

    Notices?