Harry Putnam wrote:
I want to know if doing something like what is in the code below would
be expensive or for some other reason a bad choice.
There is more code, that either feeds the `find()' function or further
processes the results of the `find()' part. The code is not in
finished form, or tested, but more to show what I'm trying to do.
There are, probably unnecessary, comments to try to show intent.
I want to be able to pass in a regex to find specific directories and
a regex to find things in the text of numeric named files in those
directories.
The passing part will probably be done with getopts standard. Or just
a shift of two expected args. That part is not what I'm asking about.
I'm more concerned with how the code would plow through a directory
hierarchy.
This would be in a directory hierarchy that would contain many levels
such as a News hierarchy, where each segment of a newsgroup name is a
level that may contain many branches and possibly many thousands of single
messages in each level and branch.
A place where you might want to pass in the regex `linux\.' to search
only the newsgroups below linux in the hierarchy, for the text_regex
that might be in the files there.
The idea being to allow you to focus a search without having to know
the exact name of the newsgroup[s]. You would at least be searching a
group with the string `linux.' in it.
So what I'm curious about is if it would be good to `next' out if the
File::Find::dir does not contain linux\.
Like:
next if(! $File::Find::dir =~ /$dir_rgx/);
No. Because you are inside a subroutine you have to use return:
return unless $File::Find::dir =~ /$dir_rgx/;
Or perhaps:
return if $File::Find::dir !~ /$dir_rgx/;
or
Like I've done in he code below. Just let the dir_rgx be a selector
and not worry about pulling the next line immediately.
I've thought about using `stat' to allow only directories into the
first directory based test as a further way to help focus things. But
not sure any of this will help speed things up.
$File::Find::dir will *only* contain directory names so such a test is
not needed.
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/