Search Unity

is this a working highscore perl script?

Discussion in 'Scripting' started by D3Jason1, Mar 29, 2013.

  1. D3Jason1

    D3Jason1

    Joined:
    Feb 18, 2012
    Posts:
    125
    Code (csharp):
    1.     #!C:\Perl\bin\perl
    2.     use strict;
    3.     use CGI;
    4.     use DBI;
    5.     # Read form data etc.
    6.     my $cgi = new CGI;
    7.     # The results from the high score script will be in plain text
    8.     print $cgi->header("text/plain");
    9.     my $playerName = $cgi->param('playerName');
    10.     my $score = $cgi->param('score');
    11.     # Connect to a database
    12.     my $dbh = DBI->connect( 'DBI:mysql:####', '####', '####' )
    13.         || die "Could not connect to database: $DBI::errstr";
    14.     # Insert the player score if there are any
    15.     if( $playerName  $score) {
    16.         $dbh->do( "insert into scores (Player, Score) values(?,?)",
    17.             undef, $playerName, $score );
    18.     }
    19.     # Fetch the high scores
    20.     my $sth = $dbh->prepare(
    21.         'SELECT player, score FROM scores ORDER BY score desc LIMIT 10' );
    22.     $sth->execute($Player);
    23.     while (my $r = $sth->fetchrow_arrayref) {
    24.         print join(':',@$r),"\n"
    25.     }
    need a working one without using a pointless game variable
     
  2. Foam

    Foam

    Joined:
    Jun 13, 2012
    Posts:
    322
    Looks fine to me but what "game variable" are you referring to?

    Also, this isn't the place to ask for Perl advice.