Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by xdg (Monsignor)
on Apr 02, 2013 at 13:38 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1026688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-04-19 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found