Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2023-12-11 11:35 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.