in reply to Extract random records from text file
my $file = do { local $/; <FILE> }; # slurp my @questions = $file =~ /(^question.*\n(?:(?!question).*\n)*)/gm; for (1..10) { # 10 questions at random my ($one) = splice @questions, rand @questions, 1; my %param = $one =~ /^(\w+)=(.*)/gm; print $param{question}, "\n"; print "$_: ", $param{"option$_"}, "\n" for 1..4; ... etc ... }
-- Randal L. Schwartz, Perl hacker
|
|---|