Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi, there!
Can someone explain to me what is the difference between
use CGI;
and
use CGI qw(:standard);
Thank you!

Replies are listed 'Best First'.
Re: CGI Question
by gellyfish (Monsignor) on Aug 11, 2003 at 19:33 UTC

    I think in the first instance it would be best to answer the question with direct reference to the CGI module.

    If you look at the description of use in the perlfunc manpage then you will see a definition:

     
       use Module LIST
    
    
    when used like this the LIST is passed to the modules import method. In many cases this method is supplied by the Exporter module but a module author may often supply their own. The purpose of the import is essentially to cause the names supplied in LIST to be available in the calling package without needing qualification (like Module::name).

    Some modules, rather than requiring to supply each individual name to be imported individually, supply 'import tags' which signify a group of commonly used names to be imported in one go - these 'import tags' are often prefixed with a colon (':') to make it clearer that they are not the actual names that will be imported.

    The CGI module has a number of such 'import tags' of which :standard is the most commonly used: it causes the most useful methods in the module for general use to be imported. IN the documentation for the module you will find the full list of the methods that are imported.

    /J\
    
Re: CGI Question
by blue_cowdawg (Monsignor) on Aug 11, 2003 at 19:32 UTC

    with "use CGI;" you are using the module without specificly importing methods. With "use CGI qw(:standard);" you are asking CGI to export a set of methods marked by the export block :standard.

    Example code:

        #!/usr/bin/perl -w ########################################################## use strict; use warnings; use diagnostics; use CGI; my $q=new CGI; print $q->header,$q->start_html(-title=>"blah"); . . .etc.
    Another example:
        #!/usr/bin/perl -w use strict; use warnings; use diagnostics; use CGI qw @ :standard @; print header,start_html(-title=>"blah"); . . . . etc.

    FMI: man CGI


    Peter @ Berghold . Net

    Sieze the cow! Bite the day!

    Nobody expects the Perl inquisition!

    Test the code? We don't need to test no stinkin' code!
    All code posted here is as is where is unless otherwise stated.

    Brewer of Belgian style Ales