Where's the problem with this code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sam Snead

    Where's the problem with this code?

    Hey, I've been having some trouble debuggin this...I keep getting 500
    errors. Would some kind soul be willing to help me?

    #!/usr/bin/local/perl

    print "Content-type: text/html\n\n";

    read(STDIN, $buffer, $ENV{'CONTENT_L ENGTH'});
    @pairs = split(/&/, $buffer);
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
    }

    if ($FORM{'subitte d'} eq 'yes' )
    showstats();
    else
    {


    print <<EndOfHTML;
    <html><head><ti tle>Test Page</title></head>
    <body>
    <h2>Select User</h2>
    <form action='./logger.cgi' method=post>
    <input type=hidden name=submitted value='yes'>
    <select name='userid'>

    EndOfHTML

    opendir(DIR, ".");
    @files = readdir(DIR);
    closedir(DIR);

    foreach $file (@files)
    {
    if ($file ne "." && $file ne ".." && $file ne "logger.cgi ")
    {
    print "<option value=";
    print $file;
    print ">";
    print $file;
    print "</option>\n";
    }
    }

    print "</select><br><inp ut type=submit></form>";

    }

    sub showstats()
    {
    %datahash = {};
    @timeofday[96];
    foreach $entry(@timeofd ay)
    $entry=0;
    @tempbuffer;
    open(INFILE,$FO RM{'userid'});
    @data = <INFILE>
    foreach $line (@data)
    {
    @tempbuffer = split(/=/, $line)
    $datahash{@temp buffer[0]}=@tempbuffer[1];
    if ($datahash{@tem pbuffer[0]}==1)
    {
    $numberofdays = @tempbuffer[0] % (24 * 60 * 60);
    $tod = @tempbuffer[0] - $numberofdays * 24 * 60 *
    60;
    @timeofday[$tod/(24*4)]++;
    }
    }




    print "<html><hea d></head><body>\n";
    foreach $entry(@timeofd ay)
    {
    print "<img src=http://www.shehan.ws/images/red.gif width=4
    height=";
    print $entry;
    print ">\n";
    }
    }


  • Roel van der Steen

    #2
    Re: Where's the problem with this code?

    On Sun, 21 Mar 2004 at 01:15 GMT, Sam Snead <samsnead@sammy .com> wrote:[color=blue]
    > Hey, I've been having some trouble debuggin this...I keep getting 500
    > errors. Would some kind soul be willing to help me?
    >
    > #!/usr/bin/local/perl[/color]

    use strict;
    use warnings;
    [color=blue]
    >
    > print "Content-type: text/html\n\n";[/color]
    <some code snipped>[color=blue]
    > else
    > {
    >
    > print <<EndOfHTML;
    > <html><head><ti tle>Test Page</title></head>
    > <body>
    > <h2>Select User</h2>
    > <form action='./logger.cgi' method=post>
    > <input type=hidden name=submitted value='yes'>
    > <select name='userid'>
    >
    > EndOfHTML[/color]
    .. . . . ^^^^^^^^^
    Hey! this is not what you said that your here document would end
    with. Either move this marker to the left, or change your print
    statement as follows:

    print <<' EndOfHTML';

    I guess that this will cure most of your problems...

    Comment

    • Sam Snead

      #3
      Re: Where's the problem with this code?

      In article <slrnc5qhg8.atk .roel-perl@195-86-124-242.dsl.easynet .nl>,
      roel-perl@st2x.net says...[color=blue]
      > On Sun, 21 Mar 2004 at 01:15 GMT, Sam Snead <samsnead@sammy .com> wrote:[color=green]
      > > Hey, I've been having some trouble debuggin this...I keep getting 500
      > > errors. Would some kind soul be willing to help me?
      > >
      > > #!/usr/bin/local/perl[/color]
      >
      > use strict;
      > use warnings;
      >[color=green]
      > >
      > > print "Content-type: text/html\n\n";[/color]
      > <some code snipped>[color=green]
      > > else
      > > {
      > >
      > > print <<EndOfHTML;
      > > <html><head><ti tle>Test Page</title></head>
      > > <body>
      > > <h2>Select User</h2>
      > > <form action='./logger.cgi' method=post>
      > > <input type=hidden name=submitted value='yes'>
      > > <select name='userid'>
      > >
      > > EndOfHTML[/color]
      > . . . . ^^^^^^^^^
      > Hey! this is not what you said that your here document would end
      > with. Either move this marker to the left, or change your print
      > statement as follows:
      >
      > print <<' EndOfHTML';
      >
      > I guess that this will cure most of your problems...
      >[/color]
      Oh, thank you very much!

      Comment

      • Grygory Tertychny

        #4
        Re: Where's the problem with this code?


        "Sam Snead" <samsnead@sammy .com> :[color=blue]
        > Hey, I've been having some trouble debuggin this...I keep getting 500
        > errors. Would some kind soul be willing to help me?[/color]
        ...[color=blue]
        > if ($FORM{'subitte d'} eq 'yes' )
        > showstats();
        > else
        > {[/color]

        must be:

        if ($FORM{'subitte d'} eq 'yes' )
        {
        showstats();
        }
        else
        {

        --
        Grygory Tertychny


        Comment

        • Sam Snead

          #5
          Re: Where's the problem with this code?

          In article <c3msqe$28f$1@n ews.kiev.sovam. com>, milon@svitonlin e.com
          says...[color=blue]
          >
          > "Sam Snead" <samsnead@sammy .com> :[color=green]
          > > Hey, I've been having some trouble debuggin this...I keep getting 500
          > > errors. Would some kind soul be willing to help me?[/color]
          > ...[color=green]
          > > if ($FORM{'subitte d'} eq 'yes' )
          > > showstats();
          > > else
          > > {[/color]
          >
          > must be:
          >
          > if ($FORM{'subitte d'} eq 'yes' )
          > {
          > showstats();
          > }
          > else
          > {[/color]
          Thanks, I thought that it would work like C where you don't need braces
          for one line, but I was wrong.

          Trey

          Comment

          Working...