Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: File::Glob infinite loop with while loop unlike core glob function

by jpl (Monk)
on Aug 01, 2011 at 14:29 UTC ( #917861=note: print w/replies, xml ) Need Help??

in reply to File::Glob infinite loop with while loop unlike core glob function

One, perhaps final, comment. In the process of writing a short program to reproduce the behavior (in case someone, probably me, decides to file a bug report, my earlier whinging notwithstanding), I came up with this:
#!/usr/bin/perl -w use strict; use File::Glob ':glob'; my $dir = shift || "/etc"; my $max = shift || 10000; my $entries = 0; while (glob("$dir/*")) { last if (++$entries > $max); } print($entries, " items under $dir\n");
If I comment out the use File::Glob ':glob'; to get a run with the core glob, then put it back in, I see the following
time /etc 20000 279 items under /etc real 0m0.00s user 0m0.00s sys 0m0.00s time /etc 280 281 items under /etc real 0m0.15s user 0m0.09s sys 0m0.06s
The first (core) run demonstrates that there are 279 entries in my /etc, and it takes almost no time to determine that. The second run, confined to stop after it is demonstrably wrong, takes quite a while to be wrong. This is consistent with it rebuilding the entire list for each iteration, then throwing away all but the last item.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://917861]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2016-10-28 05:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (375 votes). Check out past polls.