in reply to Redirect and using CGI constructor

You need to set $subject to some value first (strict will not allow the code to run otherwise.) Try this:
use CGI; use strict; my $query = CGI->new(); my $subject = $query->param( 'subject' ); unless( defined $subject && $subject ) { ...
The calling convention of my $query = CGI->new(); is generally prefered, your way (my $query = new CGI;)is deprecated.

You should test that subject is both defined and that it has some value, as $subject = '' is defined but probably not what you want. You might want a regex like $subject =~ m/\w+/;to test that there are some characters in subject at the very least.

My question is $query an object instance of new CGI constructor? $query is now an instance of the CGI object and so it allows you access to the CGI modules methods.

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Re: Redirect and using CGI constructor
by Anonymous Monk on Nov 17, 2003 at 16:03 UTC
    sorry i forgot to add I did have a place where value is declared:
    my $subject = param('subject');
    Also the
    my $query = CGI->new();
    $query is an instance of the CGI contstructor and/or is it a reference to CGI constructor?
      If you really want to know:

      $query is a reference to a hash, and this hashref is blessed into the class CGI. Try running this one liner:

      perl -e 'use CGI; $cgi = CGI->new; print $cgi, "\n\n";'

      The CGI->new() is simply a way of saying run the method 'new' of the module 'CGI'. This method returns the blessed hashref above.

      This can all get really confusing in the beginning, try perldoc perltoot for a fairly nice introduction.

      --tidiness is the memory loss of environmental mnemonics

        Thanks EvdB!