Harry wrote:
This new coding although easier to look at and probably more efficient, isn't really any faster or at least not appreciably. It still goes to each and every numbered file.
John replied:
In most file systems the file names are not stored in any particular order so in order to find every file of a certain type you have to look at every file in a directory to determine if it is the type you want.
So I guess there just isn't any tricky fast way to get just the directory names then eh? This is on ext3 fs but about the only real change I could make there would be to reiserfs or something and I'll assume that wouldn't really change the problem.
A directory is just a special kind of file. Think of it as a text file with one file name per text line (in no particular order.) Now imagine that you had to find every line that contained the letter 'r'.
sub something { ... } find( \&something, @directories );
And
find( sub { ... }, @directories );
Do the same thing but the first uses a reference to a named subroutine and the second uses a reference to an anonymous subroutine.
OK, thanks for clearing that up...Is one better than the other in some way?
The first one creates an entry in the symbol table because it has a name while the second one doesn't. As to which is "better" ... it depends. :-)
use File::Spec; use File::Find;
[...]
my @top_dir = map File::Spec->rel2abs($_), splice @ARGV; my $file = './uniq_dir_under_news';
Is using File::Spec in this way, faster or more efficient than using Cwd like in the original? Or are you just showing another approach?
In the original you called getcwd() inside the find() subroutine which would call it once for every directory entry in every directory and sub-directory. My example calls File::Spec->rel2abs() for every entry in @ARGV which should be a lot more efficient.
John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>