Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^5: File::Random module (Path::Iterator::Rule)

by xdg (Monsignor)
on Apr 02, 2013 at 13:38 UTC ( #1026688=note: print w/replies, xml ) Need Help??

in reply to Re^4: File::Random module (Path::Iterator::Rule)
in thread File::Random module

Use the iterator with a while loop and just keep a count (or array) of the number of randomly selected files. Use last when you have enough. Or, if you run out of files, re-generate the iterator.

For what it's worth, you can even put the randomness into the iterator:

my $rule = Path::Iterator::Rule->new->file->and(sub { rand() < 0.1 });

I just shipped PIR 1.005 to CPAN to fix broken tests on Windows.


Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^6: File::Random module (Path::Iterator::Rule)
by McA (Priest) on Apr 02, 2013 at 13:45 UTC

    Thank you for the fast reply and fixing the bug (++).

    UPDATE: Installs without error now.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2022-05-21 08:22 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (76 votes). Check out past polls.