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

I am going to produce a web page via CGI Pretty. But nothing occuied. Please help me!
#!C:/Perl/bin/perl use strict; use CGI::Pretty qw( -debug ); use CGI::Carp qw( fatalsToBrowser ); my $q = new CGI; my $pay = $q->param(payment=>"discover","master","check"); my $pay_text; if ( $pay eq "discover" ) { $pay_text = "Discover Card"; } elsif ( $pay eq "discover" ) { $pay_text = "Master Card"; } elsif ( $pay eq "check" ) { $pay_text = "by check"; } else { $pay_text = "unknown method"; } print $q->header, $q->start_html( -title=>"Welcome", -bgcolor=>"pink"), $q->p( "Your name is ", $q->b("name")), $q->p( { -style=>{yext-decortation:underline}, "Your age is ", $q->textfield(-name=>"age")), $q->p( "Your method of payment is ", $q->span($pay_text),-style=>{color=>"blue"}) $q->end_html;

Edited (davorg): replaced [code] tags with <code> tags

Replies are listed 'Best First'.
Re: Can't produce a web page via CGI
by Melly (Chaplain) on Nov 23, 2006 at 16:56 UTC

    I'm not quite sure what you're trying to do with the form params, but you have several errors in either your perl syntax or your html/css syntax (yext-decortation is normally spelled slightly differently;).

    When passing css to an html element, the syntax is close but not exactly the same as you've used.

    Try:

    #!C:/Perl/bin/perl use strict; use CGI::Pretty qw( -debug ); use CGI::Carp qw( fatalsToBrowser ); my $q = new CGI; my $pay = $q->param(payment=>"discover","master","check"); my $pay_text; if ( $pay eq "discover" ) { $pay_text = "Discover Card"; } elsif ( $pay eq "discover" ) { $pay_text = "Master Card"; } elsif ( $pay eq "check" ) { $pay_text = "by check"; } else { $pay_text = "unknown method"; } print $q->header, $q->start_html( -title=>"Welcome", -bgcolor=>"pink"), $q->p({-style=>'text-decoration:underline;'},"Your name is ",$q- +>b("name")), $q->p("Your age is ", $q->textfield(-name=>"age")), $q->p("Your method of payment is ", $q->span({-style=>'color:blu +e;'},$pay_text)), $q->end_html;
    Tom Melly, tom@tomandlu.co.uk
Re: Can't produce a web page via CGI
by davorg (Chancellor) on Nov 23, 2006 at 16:23 UTC

    If you put <code> tags (not [code] tags) around your code, then it would be easier to see what you are trying to do.

    I think the problem is with your use of the "param" function. I'm not sure how you think it works, but your usage looks like you're trying to set parameter values where I think you want to get them.

    I think that you want to replace:

    my $pay = $q->param(payment=>"discover","master","check");

    with:

    my $pay = $q->param('payment');
    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Can't produce a web page via CGI
by reasonablekeith (Deacon) on Nov 23, 2006 at 16:38 UTC
    Your parentheses don't match. Try commenting out the last half of your print statement (6 lines or so). It should at least run then. Then add rest back in till you spot your mistakes.
    ---
    my name's not Keith, and I'm not reasonable.
Re: Can't produce a web page via CGI
by brian_d_foy (Abbot) on Nov 23, 2006 at 21:20 UTC

    Try going through the steps I list in Troubleshooting Perl CGI scripts or brian's Guide to Solving Any Perl Problem. If that doesn't lead to a solution, at least you'll be able to explain the problem better.

    You might also want to try some simple, command line scripts to learn how CGI.pm works. That removes the complexity of the web interface, etc, so you can play with new features. The CGI.pm docs have some examples of how to do this.

    Good luck :)

    --
    brian d foy <brian@stonehenge.com>
    Subscribe to The Perl Review