Both, glob and readdir will end up calling the same underlying C function
use strict; use warnings; use Cwd; use Benchmark; my $dir = 'c:/windows'; my ( @a1, @a2 ); timethese 1, { glob => sub { my $cwd = getcwd; chdir $dir; @a1 = glob '*/*'; chdir $cwd; }, read => sub { my $cwd = getcwd; chdir $dir; opendir my $h, '.' or die; my @a = grep { $_ ne '.' and $_ ne '..' and -d $_ } readdir $h +; for my $d ( @a ) { opendir my $hh, $d or next; push @a2, map "$d/$_", grep { $_ ne '.' and $_ ne '..' } readdir $hh; } chdir $cwd; } }; use Test::More; is $#a1, $#a2, 'array lengths are equal' or do { use Test::Differences; eq_or_diff [ sort @a1 ], [ sort @a2 ], 'look deeper', { context => 0 };; }; done_testing;

I don't care much about 7 (out of ~27e3) entries missing in one case (something to do with leading dot in a name), but I wonder if orders of magnitude speed difference is what OP is observing for his large tree. My Perl's latest Strawberry, + fast NVMe storage.

Benchmark: timing 1 iterations of glob, read... glob: 4 wallclock secs ( 0.30 usr + 3.34 sys = 3.64 CPU) @ 0 +.27/s (n=1) (warning: too few iterations for a reliable count) read: 0 wallclock secs ( 0.03 usr + 0.06 sys = 0.09 CPU) @ 10 +.53/s (n=1) (warning: too few iterations for a reliable count) not ok 1 - array lengths are equal # Failed test 'array lengths are equal' # at glob.pl line 39. # got: '27633' # expected: '27640' not ok 2 - look deeper # Failed test 'look deeper' # at glob.pl line 41. # +----+-----+----+-------------------------------------------+ # | Elt|Got | Elt|Expected | # +----+-----+----+-------------------------------------------+ # | | * 656| 'INF/.NET CLR Data', * # | | * 657| 'INF/.NET CLR Networking', * # | | * 658| 'INF/.NET CLR Networking 4.0.0.0', * # | | * 659| 'INF/.NET Data Provider for Oracle', * # | | * 660| 'INF/.NET Data Provider for SqlServer', * # | | * 661| 'INF/.NET Memory Cache 4.0', * # | | * 662| 'INF/.NETFramework', * # +----+-----+----+-------------------------------------------+ 1..2 # Looks like you failed 2 tests of 2.

In reply to Re^2: smart glob of dated subfolders by Anonymous Monk
in thread smart glob of dated subfolders by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.