Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Extract random records from text file

by jeroenes (Priest)
on Oct 02, 2001 at 20:28 UTC ( #116178=note: print w/ replies, xml ) Need Help??


in reply to Extract random records from text file

Look again at rand and perlvar.

use POSIX qw/floor/; local $/= '==='; my @allquestions = <QUESTIONS>; my @questions; for (1..$maxcount){ my $idx = floor rand @allquestions; push @questions, splice @allquestions, $idx, 1; } return @questions;

Than you'll have to solve your delimiter problem. Dunno what it is, run some checks on that. (We're discussing that in CB right now) And, of course, use strict and warnings.

Jeroen
"We are not alone"(FZ)

Update I added the local thing... too important to miss out... read Why or why not? - local undef $/ and Use strict warnings and diagnostics or die eg.

Update 2 merlyn made me realize (again) that you don't need to floor the stuff:

local $/= '==='; my @allquestions = <QUESTIONS>; my @questions; push @questions, splice @allquestions, rand @allquestions, 1 for (1..$ +maxcount) return @questions;


Comment on Re: Extract random records from text file
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-08-27 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (232 votes), past polls