Thread: CGI Help

  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2016
    Rep Power

    Exclamation CGI Help


    My assignment calls for me to output a range of numbers from highest to lowest but it must be from the user input. Where I'm confused is that I know how to display an array, however, I'm unsure if I'm starting my code off right by using a for loop.

    Create a CGI application with an HTML page named myform.html and a CGI script named myscript.cgi. The HTML page's form has two textboxes for entering the upper and lower values for a range of consecutive integers. Complete the form by choosing values that differ by about 10. Submitting the form should execute myscript.cgi. The script should output an unordered list showing all of the integers in the range from highest to lowest.

    use strict;
    use warnings;
    use CGI qw(:standard);
    use CGI::Carp qw(fatalsToBrowser);
    print "Content-type: text/html\n\n";
    #read form input from user
    my $userinput = <STDIN>;
    my $low = param ('lowest');
    my $high = param ('highest');
    foreach (my $userinput < 100){
    	print "$low && $high" ;}
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Apr 2009
    Rep Power
    Why do you have this line?
    my $userinput = <STDIN>
    Using a for/foreach loop is correct but you're initializing it wrong.

    What version of perl are you using?
    use 5.010;
    use warnings;
    use strict;
    my $high = 10;
    my $low = 1;
    say '<ul>';
    say "\t<li>$_<\li>" for (reverse $low .. $high);
    say '</ul>';
    That loop could also be written as
    for (reverse $low .. $high) {
        say "\t<li>$_<\li>";
    or as Mikkel showed you in your cross post on stackoverflow
    for (my $i=$high; $i>= $low; $i--) {
        print qq{    "<LI>$i</LI>\n};
    Last edited by FishMonger; November 6th, 2016 at 03:26 PM.

IMN logo majestic logo threadwatch logo seochat tools logo