[Ilugc] More perl and CGI

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Sun, 23 Dec 2012 19:33:31 +0530

CGI and perl have always enjoyed a nice marriage.

I find it incredibly easy to do simple things over the web.

You need glue code with jQuery and javascript browser frontend to go with it.

Most cases don't even require that.

We saw how to obtain dynamic output from CGI and perl last time.

Now we will see how to obtain user input and process it.

That will be nice.

Simple DB query, search, e-mail sending and feedback processing, quizzes,
 ratings, simple interfaces all depend on this.

Let us look at something from the CGI.pm man page itself.

You must get into the habit of looking at man pages and the examples in them
 to get started.

Reading man pages and making sense takes lot of experience, patience
and knowledge.

No other reference is good. You have to count on web and man pages...

Here is the sample:

# cat ilugsample.pl
#!/usr/bin/perl

 use CGI qw/:standard/;
          print
              header,
              start_html('Simple Script'),
              h1('Simple Script'),
              start_form,
              "What's your name? ",textfield('name'),p,
              "What's your relationship with LUG?",
              checkbox_group(-name=>'words',

-values=>['casual','serious','student','entrepreneur']),

              p,"What's your favorite OS?",
              popup_menu(-name=>'color',
                         -values=>['Linux','Windows','Mac','Other']),p,
              submit,
              end_form,
              hr,"\n";

           if (param) {
              print
                  "Your name is ",em(param('name')),p,
                  "Your relationships are: ",em(join(", ",param('words'))),p,
                  "Your favorite OS is ",em(param('color')),".\n";
           }
           print end_html;

And see it work here:

http://www.spam-cheetah.com/cgi-bin/ilugsample.pl

-Girish
-- 
Gayatri Hitech
http://gayatri-hitech.com

Other related posts:

  • » [Ilugc] More perl and CGI - Girish Venkatachalam