Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

i'm having problems getting the following to work. can u see anything obvious that might be the culpret.
#!/usr/local/bin/perl -W use CGI qw(standard); use CGI::Carp qw(fatalsToBrowser); use DBI; use Getopt::Std; use CGI::Request; ##initialise oracle connection $ENV{‘ORACLE HOME’)= ‘/oracle/uo1’; $host = “neptune”; $sid = “ora1”; $user = “tayloja1”; $password = “the.best”; $sport = ‘basketball’; my $cgi = new CGI::Request; my $year =$cgi->param("year"); my %teams; $teams{"team$_"} = param("team$_") for 1..11; foreach $team (keys %teams) { If ($team ne ‘please specify’){ Push @list1,$team1; } } ##Once the list is created I need to randomise the array. $firstrandom = $list1 [rand @list1]; Push @list2, $random; $count = $#list1 while ($count != 0){ ###create list2 $random = $list1 [ rand @list1]; $present = “false”; For $I (0..$#list2){##check to see if team is already in list If ($random == $list2[$I]) { $Present == ‘true’; }; If ($Present == ‘false’) { ##if not add it to @list2 Push @list2, $random; $count--; }; }; Database creation ## connect to oracle database. my $dbh = DBI->connect( "dbi:Oracle:host=$host;sid=$sid",$username, $p +assword) || die "Can't connect to Oracle"; For $I (0..$#list2) { $teampos = $I + 1; my$sth = $dbh->do("INSERT INTO results VALUES('$year',‘$sport’,‘$list2 +[$I],‘0’)") || die "Can't execute SQL insert results statement"; my$sth2 = $dbh->do("INSERT INTO trees VALUES('$year',‘$sport’, ‘$teamp +os’,‘$list2[$I]’,‘0’)") || die "Can't execute SQL insert trees statem +ent"; For $I (1..$#list2){ $teampos = $I + $#list2+1; my$sth3 = $dbh->do("INSERT INTO trees VALUES('$year',‘$sport’, ‘$teamp +os’,‘TBA’,‘0’)") || die "Can't execute SQL insert trees statement"; } my $compsize = $#list2+1; my $sth4 = $dbh->do("INSERT INTO compsize VALUES('$year',‘$sport’, ‘$c +ompsize’)") || die "Can't execute SQL insert results statement"; my $sth5 = $dbh->prepare("SELECT round, teamname, score from trees whe +re sport = ‘$sport’ and year = ‘$year’, ORDER BY round DESC") || die +"Can't prepare SQL get data statement"; $sth5->execute || die “can’t execute sql statement”; ##need to get all the data one row at a time from the table. my @row; $rowcount = 0; while (@row = $sth5->fetchrow_array()) { $round = $row[0]; $teamname = $row[1]; ## need to put each row into the list. $Score = $row[2]; of lists a variable at a time push (@{list_of_teamdata[$rowcount]}, qw($round $teamname $score); $rowcount++; } my $compsize = $#list2+1; If ($compSize = 7); Print “Content-Type: text/html\n\n”; Print “<html>\n”; Print “<head>\n”; Print “<title> tree7</title>\n”; Print “</head>\n”; Print “<body>\n”; Print “<table border="1" width="100%">\n”; Print “<tr>\n”; Print “<td width="9%">&nbsp;</td>\n”; Print “<td width="9%">&nbsp;</td>\n”; Print “<td width="9%">&nbsp;</td>\n”; Print “<td width="9%"><b><P align=center><SELECT name=Team7 size=1>\ +n”; Print “<OPTION selected value=101>$list_of_teamdata [6][1]</OPTION>\ +n”; Print “<OPTION value=103>Business School</OPTION>\n”; Print “<OPTION value=103>Admin/Estates</OPTION>\n”; Print “<OPTION value=104>CEAC </OPTION>\n”; Print “<OPTION value=105>Civ Eng</OPTION>\n”; Print “<OPTION value=106>Combined Honours</OPTION>\n”; Print “<OPTION value=107>CSAM</OPTION>\n”; Print “<OPTION value=108>EEAP</OPTION>\n”; Print “<OPTION value=109>MechEng</OPTION>\n”; Print “<OPTION value=110>ModLang</OPTION>\n”; Print “<OPTION value=111>Vision Sciences</OPTION>\n”; Print “<OPTION value=112>Pharmacy</OPTION>\n”; Print “&nbsp;</SELECT>\n”; Print “</P>\n”; Print “</td>\n”; Print “</b>\n”; Print “</td>\n” Print “<td width="9%"><b><P align=center><SELECT name=score7 size=1> +\n”; Print “<OPTION selected value=101>$list_of_teamdata [6][2]</OPTION>\ +n”; Print “<OPTION value=103>0</OPTION>\n”; Print “<OPTION value=103>1</OPTION>\n”; Print “<OPTION value=104>2</OPTION>\n”; Print “<OPTION value=105>3</OPTION>\n”; Print “<OPTION value=106>4</OPTION>\n”; Print “<OPTION value=107>5</OPTION>\n”; Print “<OPTION value=108>6</OPTION>\n”; Print “<OPTION value=109>7</OPTION>\n”; Print “<OPTION value=110>8</OPTION>\n”; Print “<OPTION value=111>9</OPTION>\n”; Print “<OPTION value=112>10</OPTION>\n”; Print “<OPTION value=113>11</OPTION>\n”; Print “<OPTION value=114>12</OPTION>\n”; Print “&nbsp;</SELECT>\n”;

Replies are listed 'Best First'.
Re: cgi problem
by busunsl (Vicar) on Mar 26, 2001 at 23:16 UTC
    Well, the first error is to not use strict

    Otherwise you would have seen the error in

    foreach $team (keys %teams) { If ($team ne ?please specify?){ Push @list1,$team1; } }
    There is no variable $team1, it should be $team!
Re: cgi problem
by myocom (Deacon) on Mar 27, 2001 at 00:26 UTC

    The folks above both have fine advice, but you have a rather more serious problem going on as well. Perl is case-sensitive, and its built-in keywords, functions, etc. are all lowercase. Things like Print, If, For, etc. will get you nowhere fast.

    I imagine that's your most immediate problem, at least, as Perl will fail to compile this script as written.

      Plus Perl and SQL want their 'quotes' to be quotes and not "Microsoft smartquotes" so stuff like ‘$sport’ and $present = “false”; are going to cause problems as well.

              - tye (but my friends call me "Tye")
        i do have a syntax error on the following but i can't see the problem. i used the qutes that you suggested and there is still an issue.i'm very new to perl and this is the first script i have written so could u please help me out?? i need to randomise the contents of an array with the following i'm and am trying to suss out the syntax error i keep getting at the assignment step
        $ispresent = 'false'
        heres the code
        Once the list is created I need to randomise the array. $firstrandom = $list1[rand @list1]; push @list2, $random; $count = $#list1 while ($count != 0){ ###create list2 $random = $list1[rand @list1]; $ispresent = 'false'; for $I (0..$#list2){##check to see if team is already in list if ($random == $list2[$I]) { $ispresent = 'true'1}; }; if ($ispresent =='false') { ##if not add it to @list2 push @list2, $random; $count--; }; };
Re: cgi problem
by little (Curate) on Mar 26, 2001 at 23:19 UTC
    I don't get why and what for you need the colonna of prints in the end of your script. Let CGI.pm do that stuff for yozu, so you need fewer prints. And which errors do you get ?? Where? And why don't you use strict?

    Have a nice day
    All decision is left to your taste
    Update
    You also have some my declarations inside "For" loops, so they get a value assigned but can't carry that outside their scope.