473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to select 10 questions out of 20 in an array

How to select 10 questions out of 20 in an array and i only want each question once

i have
Expand|Select|Wrap|Line Numbers
  1. sub BuildFeedbackPage{
  2.   my @questions = &Questions(10);
  3.   print hr, $1, br;
  4.   print radio_group(-name=>'question1', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels); #radiobuttons group 1 - 5
  5.   print hr, $2, br;
  6.   print radio_group(-name=>'question2', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  7.   print hr, $3, br;
  8.   print radio_group(-name=>'question3', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  9.   print hr, $4, br;
  10.   print radio_group(-name=>'question4', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  11.   print hr, $5, br;
  12.   print radio_group(-name=>'question5', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  13.   print hr, $6, br;
  14.   print radio_group(-name=>'question6', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  15.   print hr, $7, br;
  16.   print radio_group(-name=>'question7', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  17.   print hr, $8, br;
  18.   print radio_group(-name=>'question8', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  19.   print hr, $9, br;
  20.   print radio_group(-name=>'question9', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  21.   print hr, $10, br;
  22.   print radio_group(-name=>'question10', -values=>['very bad', 'bad', 'average', 'good', 'very good'], -default=>'average', -linebreak=>'true', -labels=>\%labels);  #radiobuttons group 1 - 5
  23.   print hr, &MakeSubmitButton('Finished');
  24. }
  25. sub Questions{
  26.   my $1 = '';
  27.   my $2 = '';
  28.   my $3 = '';
  29.   my $4 = '';
  30.   my $5 = '';
  31.   my $6 = '';
  32.   my $7 = '';
  33.   my $8 = '';
  34.   my $9 = '';
  35.   my $10 = '';
  36.   my $11 = '';
  37.   my $12 = '';
  38.   my $13 = '';
  39.   my $14 = '';
  40.   my $15 = '';
  41.   my $16 = '';
  42.   my $17 = '';
  43.   my $18 = '';
  44.   my $19 = '';
  45.   my $20 = '';
  46.  
  47.   my @questions = '$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20';
  48.   for(my $i=0; i<10; i++)
  49.   {
  50.     if(
  51.     my @return += int(rand(@questions));
  52.  
  53.   }
  54.   return @return;
  55. }
  56. sub GetRating{
  57.   my $0 = shift;
  58.   my $1 = shift;
  59.   my $2 = shift;
  60.   my $3 = shift;
  61.   my $4 = shift;
  62.   my $5 = shift;
  63.   my $6 = shift;
  64.   my $7 = shift;
  65.   my $8 = shift;
  66.   my $9 = shift;
  67.   my $rating = ((($0 + $1 + $2 + $3 + $4 + $5 + $6 + $7 + $8 + $9) * 2) / 10);
  68.   return $rating;
  69. }
  70. sub StoreRatingToFile{
  71.   my $rating = GetRating(param('question1'), param('question2'), param('question3'), param('question4'), param('question5'), param('question6'), param('question7'), param('question8'), param('question9'), param('question10'));
  72.   my $email = #hidden textfield containing email address from log in
  73.   open(OUTFILE, ">>", "$outfile");
  74.   print OUTFILE "$rating : $email";
  75.   close OUTFILE;
  76. }
  77.  
Nov 25 '10 #1
1 1372
chorny
80 Expert
10 random entries? Use shuffle from List::Util and then select first 10.
Nov 25 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: dr. zoidberg | last post by:
Hello, I have mysql table: +----+---------+ | 1 | value1 | +----+---------+ | 2 | value2 | +----+---------+ | 3 | value3 |
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
7
by: Fabian Wauthier | last post by:
Hi list, I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of pointers to a struct Atom (i.e. the head of a linked list). I am not sure if this is the right way to do it: ...
3
by: george r smith | last post by:
I am converting a delphi chess program to C#, this is how I study a new language and I have the following problem. How do you use an enumeration value as an indexer for an array ? This is what I...
0
by: Markus S. | last post by:
Hello! I have two questions about Socket.Select(): 1) How is it possible to interrupt Socket.Select()? I'm calling Socket.Select() in a worker thread. When new sockets are added (from another...
7
by: Jake Thompson | last post by:
Hello I have the following defined structure struct cm8linkstruc { char *type; /* type of item*/ char *desc; /* description of item ...
3
by: Madhu | last post by:
I would like to know how the following will be handled in the .net framework: Pl. don't pay attention to the syntax int a int b a=2 a=2 a=2
12
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown...
0
by: DR | last post by:
is there any speed difference between a TVF CLR that returns an array vs yield as each result is ready? e.g. does returning the array all at once cause sql server to allocate more efficiently?
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.