[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Help with Perl/CGI



On Wednesday 23 October 2002 4:11 pm, Alex Hudson wrote:
> On Wed, Oct 23, 2002 at 03:52:26PM +0100, Steve Tickle wrote:
> > #!/usr/bin/perl;
> >
> > my $input;
> >
> > $input = param('input');
> >
> > print "Content-type: text/html\n\n";
> > print "You typed '$input'\n";
>
> Should be:
>
> #!/usr/bin/perl -w
> use strict;
> use CGI;
> use CGI::Carp qw( fatalsToBrowser );
>
> my $cgi = new CGI;
> my $input = $cgi->param ('input');
>
> print $cgi->header (-type=>'text/html'),
> 	qq{ <html><body><p>You typed: $input</p></body></html> };
>
> --------------
> -w and use strict make Perl check your program more thoroughly - most
> recommended. The CGI::Carp line makes Perl chuck errors to your
> browser rather than your logs - so you see a message, rather than
> a big "500". The CGI module is what you're trying to use, but you never
> actually loaded it. So here, we 'use..' it and then instatiate a cgi
> object, called $cgi. You then call the param method of this object.
>
> qq{..} is fancy for "..." (often used with HTML, since you want to use
> " within tags, but don't particularly want to write \"), and the header
> function prints out your "Content-type:", but in a nicer way.
>
> Make sense?

Indeed it does, many thanks all.

-- 
Steve Tickle
___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.