in reply to How do I read all files in a directory recursively?
Two comments: first, I'm not sure if that's what the OP wanted at all. It's a rather useful idiom nonetheless. Second, this would have been a much more elegant solution had I made recurse_dir receive a subref and return a closure that recursively applied this subref to each file (as one would do in Scheme, e.g.). Unfortunately, this causes serious scope issues, especially if one chooses to use strict;sub process_file { open F, shift; # ...do stuff with F... close F; } sub recurse_dir { opendir D, shift; while (readdir D) { process_file ($_) if -f; recurse_dir ($_) if -d; } closedir D; } recurse_dir ($ARGV[0]);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Re: How do I read all files in a directory recursively?
by Anonymous Monk on Mar 04, 2000 at 04:21 UTC | |
|
RE: Re: How do I read all files in a directory recursively?
by plaid (Chaplain) on Mar 04, 2000 at 04:15 UTC |