--- Scott Lutz <[EMAIL PROTECTED]> wrote:
> Why is it when you specify different version of CGI types, ie.
> use CGI ':cgi-lib';
> use CGI ':standard';
> use CGI;
>
> that sometimes code will work, and other times you get nothing?
> Does anyone know of a good URL for reference on this?
>
> Thanks.
Scott,
Read through 'perldoc CGI' for a full explanation of what's going on.
When you 'use' a module, the extra stuff is passed as arguments to that modules import
function.
This generally tells the module to export various variables and subroutines to your
namespace.
The exact nature of the arguments tells the import function *which* variables and
functions to
export.
use CGI;
This is the standard object oriented interface. Nothing is exported to your code and
you must
instantiate a new CGI object to use the module.
use CGI ':standard';
This tells the module to export the ':standard' functions to your namespace. You can
then call
start_html() directly without needing something like $q->start_html.
use CGI ':cgi-lib';
This is used for backwards compatibility with the Perl4 cgi-lib.pl library. It's use
should be
discouraged, but it's included so that people can convert easily from the Perl4
library.
To see exactly what gets exported to your namespace, open up CGI.pm and read through
the
%EXPORT_TAGS hash. See 'perldoc Exporter' for more information about this hash and
exporting in
general.
You can stop now if you don't want to get into the gory details :)
As a side note, every once in a while people say you should use the function oriented
interface to
CGI.pm because functions are faster than object methods. This is not correct in this
particular
case. As of CGI version 2.20, the methods in CGI.pm generally start with something
like the
following:
my($self,@p) = self_or_default(@_);
The self_or_default() function call ensures that a blessed referent is always the
first argument
to every method. In other words, even with the function oriented interface, CGI.pm is
still using
objects internally. With the way the self_or_default method is coded, the OO
interface tends to
be slightly faster than the function-oriented interface (though, in practice, you're
likely not to
notice this except with large scripts).
Still, the function oriented interface is easy to use and saves typing.
Cheers,
Curtis "Ovid" Poe
=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A
__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]