in reply to How do I get my code to not repeat numbers and also sort the numbers
As a side note, might I suggest using CGI.pm or a similar module for processing web forms and outputting HTML.
Here is your sample code rewritten using CGI.pm:
#!perl use strict; use warnings; use CGI qw(:standard); my $NumberOfTickets = param('NumberOfTickets'); my $NumbersOnTickets = param('NumbersOnTickets'); my $HighestNumberOnTicket = param('HighestNumberOnTicket'); print header(), #The HTTP header start_html( -title => 'CGI/My First Form', -bgcolor => 'Blue', -text => 'white', ), p('Processing CGI form:'), p($NumberOfTickets), p($NumbersOnTickets), p($HighestNumberOnTicket); my @lotto; for(my $i_lotto = 0; $i_lotto < $NumberOfTickets; $i_lotto++){ for(my $i = 0; $i < $NumbersOnTickets; $i++){ $lotto[$i] = int(rand($HighestNumberOnTicket)) + 1; } print p("Your lottery ticket number is @lotto\n"); } print end_html(); __END__
CGI.pm does all of the parameter parsing for you and provides for much neater looking code. Relying on the order of the params being passed to your script is probably not the best idea.
|
|---|