Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

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.

-xdg

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.

    McA

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2019-05-23 13:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (144 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!