Hi Adriano,

The previous emails answered your questions, but may I strongly
recommend that you use strict, warnings, and taint checking?  These
three things, though they seem annoying at first, will save you much
grief in the long run.

For example, in the script you provided, you had the following two
lines:

  $query = CGI::new();
  print $query->header();

With most object-oriented code, those would have failed.  However, both
strict and warnings would have made it more likely that such a failure
would have been caught.

In the case of the CGI.pm module, the only reason this works is because
CGI.pm does a lot of work behind the scenes to let you use this module
in both a functional and object-oriented fashion.  It's only a
side-effect of this behavior which allowed your syntax to work.  The
proper syntax would be (assuming we're using strict and declaring our
variables):

  my $query = CGI->new;
  print $query->header;

Just to illustrate the problem, consider the following:

  #!/usr/bin/perl
  use warnings;
  use strict;

  {
      package Foo;
      sub new { bless {} => shift }
  }

  use Data::Dumper;
  print Dumper Foo::new; # Oops!  Should be Foo->new;

If you run that, because you have warnings enabled, you get the
following output:

  Use of uninitialized value in bless at test.pl line 8.
  Explicit blessing to '' (assuming package main) at test.pl line 8.
  $VAR1 = bless( {}, 'main' );

Clearly, blessing the object into package main is not what was
intended.

You may wish to read my CGI Course at
http://users.easystreet.com/ovid/cgi_course/

I cover similar issues and I also discuss the values of taint checking.

Hope this helps!

Cheers,
Ovid

-- 
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to