On Mon, May 18, 2009 at 20:36,  <r...@i.frys.com> wrote:
> Chas. Owens wrote:
>> On Mon, May 18, 2009 at 19:41, AndrewMcHorney <andrewmchor...@cox.net> wrote:
>>> Charles
>>>
>>> I am getting totally confused. All I want is a simple find function call
>>> what will return all the files that are in c:\*.*. This is on PC running
>>> windows. I thought you mentioned to use file:find() where one of the
>>> parameters would be a function which would be called once for each file
>>> found.
>> snip
>>
>> After these two lines run @files will hold every file on the c drive.
>>
>> my @files;
>> find sub { push @files, $File::Find::name if -f }, "c:/";
>>
>>
>> --
> I like and often recommend using File::Find.  However, in this case, I think
> it would be better to use backticks or qx() to call the Windows dir command.
>
> Here's a benchmark script and it's results on my system.
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> use File::Find;
> use Benchmark qw/cmpthese/;
>
> cmpthese( 10, {
>    'dir'      => sub {my @files  = `dir /b /a-d /s c:\test` },
>
>    'filefind' => sub {my @files;
>                       find sub {push @files, $File::Find::name if -f },
>                                 "c:/test"}},
> );
>
> ---
>
> C:\test>test.pl
>         s/iter filefind      dir
> filefind   1.67       --     -93%
> dir       0.119    1304%       --

10 times is not a statistical sample, if filefind ran first it is
paying the penalty of loading the information into memory.  Run a test
before the cmpthese, and then run it for a fixed set of time (using
negative values).  Other things to consider:

1. dir is not portable
2. if you want more information than just file names you will need to
parse dir's output (which makes it even less portable)

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to