in reply to Re: read directory
in thread read directory

Update: Sorry, I know this post was a bit lame and didn't prove anything

I just benchmarked the difference between "glob" and "<>" and found very little difference (subsequent runs flip-flopped which was faster). If that's the case, then I'd prefer the glob('pending/*') over the <pending/*> call because of the awkward bare word. But then, thats just me.

#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); cmpthese( 20_000, { '<>' => sub { my @results = <pending/*>; }, 'glob' => sub { my @results = glob('pending/*'); }, }, );
and the results
Rate glob <> glob 7194/s -- -0% <> 7220/s 0% --

-biz-

Replies are listed 'Best First'.
Re^3: read directory
by shmem (Chancellor) on Jul 08, 2006 at 14:28 UTC
    well, <DATA> also has a bareword.. ;-)

    I'm not surprised that glob and <> down differ much, since they are essentially the same... bigger savings can be achieved by using -M instead of (stat)[9], because doing so eliminates the overhead of making a list just to get its 10th element.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re^3: read directory
by Hue-Bond (Priest) on Jul 08, 2006 at 14:33 UTC
    I just benchmarked the difference between "glob" and "<>" and found very little difference

    That's hardly surprising since glob is the internal function implementing the "<*.c>" operator according to the documentation.

    --
    David Serrano