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

Help! I'm writing a code to display an array of data. For some reason this condition statement is causing the full script to fail. $founddex is a variable that is set to yes if an entry in the array is found that is to be amended. This routine should only be triggered when the results from a form submission has no duplicate record already in the array (@workfile), assume that $founddex is equal to "no" in this case. am_or_pm is simply a holding variable that shows what part of the day the form has been submitted in (am or pm). Can anyone tell me why this is hanging up? I'm new to the monks and any help would be appreciated :0)
if ($founddex = "no") { if ($am_or_pm eq "am") { $morntime = $formdata{'$timedata'}; $mornread = $formdata{'$readdata'}; $morneaten = $formdata{'$eaten'}; $noontime = "N/A"; $noonread = "N/A"; $nooneaten = "N/A"; } else { $noontime = $formdata{'$timedata'}; $noonread = $formdata{'$readdata'}; $nooneaten = $formdata{'eaten'}; $morntime = "N/A"; $mornread = "N/A"; $morneaten = "N/A"; } $appendedrecord=$arraydate."-".$morntime."-".$moreread."-".$morn +eaten."-".$noontime."-".$noonread."-".$nooneaten; $newdex = $#workfile; ++$newdex; $workfile[$newdex] = $appendedrecord; }

Replies are listed 'Best First'.
Re: Conditional is stopping script
by BrowserUk (Patriarch) on Apr 06, 2004 at 02:09 UTC

    This should almost certainly be

    if ($founddex eq "no")...

    Your currently doing an assignment not testing for equality.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
      Too True. I've changed that but the script is still hanging up. Any ideas?
        ...causing the full script to fail....
        Can anyone tell me why this is hanging up?

        With your giving considerably more information as to what you mean(*) by the above two statements, the short answer is "No!".

        (*) What error messages or other symptoms of failure are you recieving? In what context is the above code being called?

        You have told us "it doesn't work", but nothing else.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
Re: Conditional is stopping script
by Anonymous Monk on Apr 06, 2004 at 02:50 UTC
    I don't have perl on this machine, but it looks like $moreread should be $mornread in the assignment to $appendedrecord -- hope this helps...
      Thanks for all the comments everyone!

      Got three hours sleep, looked at it again and it was obvious. I had forgot the ';' in the statement above the if statement. I'd been staring at it for so long that I never saw it :0P

      Thanks everyone.

        Using the 'warnings' and 'strict' pragmas is a lot easier than looking for missing semicolons. ;)

        Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
Re: Conditional is stopping script
by VSarkiss (Monsignor) on Apr 06, 2004 at 02:48 UTC

    this condition statement is causing the full script to fail.
    What do you mean? Are you getting an error message? Is a message showing in your logs? Is the script dying silently? If you're getting any kind of error message, please include it. Otherwise it's next to impossible to figure out any kind of diagnosis.

      Hi!

      Sorry if I'm being a pain. I'm teaching myself perl so I'm not sure what you're needing.

      What's happening when I run the script is that the page does not display in the browser. The browser simply sits and displays nothing but a blank screen when the script is called directly from the location box of the browser.

      This is the message that I'm getting in my log relating to the file. I'm not sure where I would find the error message that you're speaking of. I'm using the sambar server on my computer and serving the documents out of it.

      127.0.0.1 - - [05/Apr/2004:23:24:42 -0400] "GET /cgi-bin/homeblood.pl? +datedata=04%2F01%2F04&eaten=no&timedata=8%3A30&shift=am&readdata=110 +HTTP/1.1" 200 0 125 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en- +US; rv:1.5) Gecko/20031007"

      I'm afraid that I don't know what it means.

      The code for the full script I'm creating is:

        Some comments:
        • There is an excellent perl module CGI that does all the hard work in parsing requests like yours and creating webpages. It's included in a typical perl distribution. For a tutorial check out this excellent piece of literature: Ovid's CGI Tutorial
        • Using hashes consequently. In your code you mix statements like this:
          $morneaten = $formdata{'$eaten'};
          with:
          $nooneaten = $formdata{'eaten'};
          The difference is that in the first line you are looking up the hash value for the literal value $eaten (including the dollar sign, because everything inside single quotes is taken literally), while in the second line you are looking up the value for eaten (without the dollar sign).
          When you would be using the CGI-module, most probably your code would look like:
          use CGI; my $query = CGI->new(); .... $nooneaten = $query->param('eaten');
        • webserver logs:
          127.0.0.1 - - [05/Apr/2004:23:24:42 -0400] "GET /cgi-bin/homeblood.pl? +datedata=04%2F01%2F04&eaten=no&timedata=8%3A30&shift=am&readdata=110 HTTP/1.1" 200 0 125 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-U +S; rv:1.5) Gecko/20031007"
          This means that your webserver has received a request to the script homeblood.pl (GET /cgi-bin/homeblood.pl), the part after the ? are your parameters, separated by &-signs (for instance 'eaten=no'). If your webserver has an error log that would be a good place to look for errors. Another way to check your script is to run in from a cmd-prompt, and see what output (and possibly errors) it will give you.
        hope this helps