Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Problems Processing Hash within Cgi Script

by EchoAngel (Pilgrim)
on Dec 22, 2004 at 15:38 UTC ( #416795=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks, I have this big hash which is created by this package. For some reason, the html code I see on the screen is everything before this code .
my %HASHDATAFROMLIBRARYFILE = MONKEY::MONKS($libraryFile); # FIRST ENTER BOX printf ("%-20s" , "Enter Animal : "); print '<select name="CellName" onChange="document.asdf.submit();">'; foreach $keys (sort keys %{$HASHDATAFROMLIBRARYFILE{TIMING}}) { print '<option value="' . $keys . '">' . $keys . '</option>' if ($ +FORM{CellName} ne $keys); print '<option value="' . $keys . '" selected >' . $keys . '</optio +n>' if ($FORM{CellName} eq $keys); } print '</select><br></br>';
So basicly, i see nothing on the screen. When I view the source code, the cgi script prints everything before this section. How do I overcome this? Should I go for another language? my Hash has a lot of process data

Replies are listed 'Best First'.
Re: Problems Processing Hash within Cgi Script
by dragonchild (Archbishop) on Dec 22, 2004 at 15:41 UTC
    1. Have you verified that your hash is being populated? Data::Dumper is your friend here ...
    2. Also, I would extract that portion of code and run it from the command line and make sure you see what you should see.
    3. Then, I would verify that the CGI script has the same environment as your commandline. For example, is it finding the same MONKEY::MONKS as the one you're finding?

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      1. Ya, there is tons of information when i dump using data::dumper 2. when i do perl myscript.cgi, i see the html output. I saved that to the another file.html and I open it in a browser and it's fine. 3. i'm sure that package works.
Re: Problems Processing Hash within Cgi Script
by bgreenlee (Friar) on Dec 22, 2004 at 16:35 UTC

    I suspect your program is dying somewhere. Check your error logs. You could also
    use CGI::Carp qw(fatalstobrowser);.


      I have found that once the code reaches this line, everything below isn't processed , but I must have the hash data create by this package! Note the resulting output from perl myscript.cgi is a valid html page!
      Okay, I finally found the problem thanks to that package/module. somewhere in that monkey package, it's trying to create a temp file, but for some reason can't. Any ideas? I gave my cgi script +777
        I would advise against giving more permissions than you have to. World writable files are something to be avoided.

        That aside, I did not see any code about opening a file. Perhaps using die would help.

        Neil Watson

Re: Problems Processing Hash within Cgi Script
by r34d0nl1 (Pilgrim) on Dec 22, 2004 at 18:09 UTC
    First I think that yoou should make sure that your hash is populated
    (something that you've probably done :p )
    Anyway I thing that the best method is to put some warnings during the processing
    in order to make sure that it is processed correct.
    Anyway another good practice is to send the html to a variable and then print it.
    It avoid to have the page breaked in the middle when an error occurs.
    Generally we would like to use something like this:
    my $html = qq {<SELECT NAME="partNumber" SIZE="1" >}; foreach my $key (sort keys %{$HASHDATAFROMLIBRARYFILE{TIMING}}) { #my $p = \%{$rpt{$HASHDATAFROMLIBRARYFILE}{TIMING}{$key}}; warn "\n Here we are $key "; # just to make sure it is executed $text .= qq { $html .= qq { <OPTION VALUE='$keys' @{[ ( ( defined($rpt{PART_NUMBER}) ) && ($FORM{CellName} eq $keys ) ) ? 'SELECTED' : '' ]} >$keys</OPTION> }; }

    I hope it could help you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://416795]
Approved by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2020-08-07 14:38 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (46 votes). Check out past polls.