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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Changes to Quiz script
by Zaxo (Archbishop) on Sep 08, 2002 at 06:27 UTC

    Please look at CGI and Template, you shouldn't handroll cgi request parsing, and all that html would be better-maintained outside the program.

    After Compline,
    Zaxo

Re: Changes to Quiz script
by Aristotle (Chancellor) on Sep 08, 2002 at 12:35 UTC
    Oh my. Too much copypasting, too little abstraction, as Common Beginner Mistakes points out. For a good tutorial on CGI, see Ovid's excellent CGI course. Lastly, as has already been suggested, use templates to pull all that ugly HTML out of the script. My personal favourite is the shooting star, Template Toolkit 2.

    Makeshifts last the longest.

Re: Changes to Quiz script
by strat (Canon) on Sep 08, 2002 at 10:31 UTC
    I prefer using
    use CGI; my $cgi = CGI::->new(); my %FORM = $cgi->Vars();
    instead of
    read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); # split the input @pairs = split(/&/, $input); # split the name/value pairs foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<([^>]|\n)*>//g; $FORM{$name} = $value; }
    because it is much more flexible and secure. What happens with your code if there are multiple checkboxes with the same name? What if a value contains the char = ?

    If you worry about the overhead of loading the CGI-Module: most often it doesn't matter at all. If it mattered, you could use CGI_Lite instead.

    Btw: is it possible for you to directly work with the hash %FORM instead of converting everything to a scalar variable?

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: Changes to Quiz script
by TStanley (Canon) on Sep 08, 2002 at 13:54 UTC
    <BlowHorn TYPE=OWN>
    You might also want to take a look at this module on CPAN
    </BlowHorn>

    TStanley
    --------
    It is God's job to forgive Osama Bin Laden. It is our job to arrange the meeting -- General Norman Schwartzkopf