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

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

by gautamparimoo (Beadle)
on Apr 02, 2013 at 10:40 UTC ( #1026650=note: print w/ replies, xml ) Need Help??


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

Thnks.. But one question .How is this rand funtion working ie what does the following statement do:

if( rand $i++ < 1 )

Sorry , I just got what it was trying to do.

One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. -Elbert Hubbard


Comment on Re^2: File::Random module (Path::Iterator::Rule)
Download Code
Re^3: File::Random module (Path::Iterator::Rule)
by marto (Chancellor) on Apr 02, 2013 at 10:46 UTC

    If you don't understand something read the documentaiton and make a short example to illustrate what it's doing in order to better understand what's going on.

    my $i=0; my $x = rand $i++; print "$x\n";

    Update: typo

      I understood the working of rand function. It calculate a random number which is checked against the if condition and if passed than the filename is given. But what if I want to specify to generate atleast 50 or 100 random files?

      One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. -Elbert Hubbard

        But what if I want to specify to generate atleast 50 or 100 random files?

        Then, like, change the function somehow, do something inside it , to keep track of more than one random filename, like some kind of a variable that has more than one thing in it ... :P

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026650]
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 2014-09-17 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls