Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Extract random records from text fileby SuperCruncher (Pilgrim) |
on Oct 02, 2001 at 20:03 UTC ( [id://116164]=perlquestion: print w/replies, xml ) | Need Help?? |
SuperCruncher has asked for the wisdom of the Perl Monks concerning the following question:
I am currently developing a generic web-based multiple choice testing system backend
for a road safety project I'm currently working on. The system, Multiple Choice
Assessment System (MCAS), has already given me a lot of problems (but BTW thanks to arturo,
clemburg, mattr and Chmrr who have already helped me out a lot!). All the questions are stored in a simple text file. A sample question looks like this: Questions in the file are delimited by \n===\n and each question may have a variable number of lines (as number of options can vary and some questions have 'visual aids' etc.) The idea is that each test has n questions (n is specified in a config file). A script is run on the main questions file that produces a preset number of 'test files'. When the system is eventually ready to 'go live', a random 'test file' is selected and converted to HTML to be displayed to the user. What I'm having trouble with now is my make_tests.pl script that, as the name implies :-) creates the 'test files'. It is meant to randomly select n questions from the main questions file and save them as a 'test file'. Thanks partially to the above monks and partially to 'The Perl Cookbook', I know have the following code (that is intended to return a random list of n questions): The function currently seems to return only lines, not whole questions. I think clemburg in particular might have warned me about this, and said that I needed some kind of 'read_record' routine but I've got no idea how to go about this (in particular, how to 'maintain state' or maintain file position between different invocations of the function). If anyone can offer any advice (or even code!), I'd greatly appreciate it.
Back to
Seekers of Perl Wisdom
|
|