www.webdeveloper.com
Results 1 to 5 of 5

Thread: Simple PERL issue.

  1. #1
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887

    Simple PERL issue.

    Hey, my PERL code is not working at all!
    I'm running the game JS Falcon, when the user gets a high score,
    I want the user to click my button to submit the highscore.
    My PERL is supposed to read the value of the "SCORE"
    and write it to a .JS file that is also located in my cgi-bin.

    HERE'S the submiting layer:
    (The DIV emerges via JavaScript when the Highscore is beaten.)
    Code:
    <DIV ID="sendLay" STYLE='position:absolute; left:48; top:-1000'>
    <FORM NAME="HIS" method="post" action="../cgi-bin/falcon_hs.pl">
    <INPUT NAME="SCORE" type="hidden" size="20">
    <INPUT NAME="B1" type="submit" value="Send HIGH SCORE" onSubmit="reload(true)">
    </FORM>
    </DIV>
    The URL of the above segment of my game is:

    http://ultimiacian.tripod.com/games/JSFalcon.html


    Then I have a PERL file in the current URL:
    http://ultimiacian.tripod.com/cgi-bin/falcon_hs.pl

    The PERL code reads:
    PHP Code:
    use ReadParse;
    &
    ReadParse;
    $jsfile="falcon_hs.js";
    $in{'SCORE'} =~ s/[^0-9a-z]//g;

    open(DAFILE"<<$jsfile");
    print 
    DAFILE "SCORE=54000";
    close(DAFILE); 
    The ReadParse.pm is:
    PHP Code:
    sub ReadParse {
      
    local (*in) = @if @_;
      
    local ($i$key$val);

      
    # Read in text
      
    if ($ENV{'REQUEST_METHOD'eq "GET") {
        
    $in $ENV{'QUERY_STRING'};
      } 
    elsif ($ENV{'REQUEST_METHOD'eq "POST") {
        
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
      }

      @
    in split(/[&;]/,$in); 

      foreach 
    $i (.. $#in) {
        # Convert plus's to spaces
        
    $in[$i] =~ s/\+/ /g;

        
    # Split into key and value.  
        
    ($key$val) = split(/=/,$in[$i],2); # splits on the first =.

        # Convert %XX from hex numbers to alphanumeric
        
    $key =~ s/%(..)/pack("c",hex($1))/ge;
        
    $val =~ s/%(..)/pack("c",hex($1))/ge;

        
    # Associate key and value
        
    $in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
        
    $in{$key} .= $val;

      }

      return 
    scalar(@in); 
    }


  2. #2
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    I didn't write the ?> part above in my ReadParse.pm.
    The 1 is the last line of that code.

  3. #3
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    My recomendation...
    Get rid of that ReadParse module altogether and start using 'strict'.

    use strict;
    use CGI; ## which comes with Perl
    my $q = new CGI;

    ## now read your form data with...
    my $score = $q->param('score'); ## that's it

    I'm not sure what you are doing here. Why include lowercase chars in a score?
    $in{'SCORE'} =~ s/[^0-9a-z]//g;

  4. #4
    Join Date
    Jan 2005
    Location
    Los Angeles, CA
    Posts
    4,887
    Originally posted by Nedals
    I'm not sure what you are doing here. Why include lowercase chars in a score?
    $in{'SCORE'} =~ s/[^0-9a-z]//g;
    That one slipped by on me un-noticed. I copied
    that statement from a different program.
    I should have used
    $in{'SCORE'} =~ s/[^0-9]//g;

    But using your recommendation I'd use
    $score =~ s/[^0-9]//g;
    after I include everything else you wrote.

    By the way, do PM files need to end with a return value?

  5. #5
    Join Date
    Dec 2002
    Location
    Pleasanton, CA
    Posts
    2,132
    ...I'd use $score =~ s/[^0-9]//g; after I include everything else you wrote.
    Correct, if you want to remove non-numeric characters
    By the way, do PM files need to end with a return value?
    They need to end with a true value, usually..

    ..code..
    1;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles