in reply to Re^4: XML tags using perl CGI
in thread XML tags using perl CGI

I am sure there is an ocean of documentation which describes it that I don't have time to read...

But you do have time to post here asking us to read the documentation for you.

CGI.pm and CGI::Carp are two completely separate modules. CGI.pm has functions that give you easy access to various data that you need in the CGI environment and also contains "HTML shortcut" functions that are supposed to make it easier to construct HTML pages. CGI::Carp contains functions which improve the error messages that you get from CGI programs. It is completely possible to use one of these modules without the other. If you are using both of these modules then you need to include a "use" statement for both of them.

When you use a module, you can give it various parameters as part of the "use" statement. These parameters can control various things. A common use of these parameters is to import various symbols into your program's main symbol table. If you see a parameter that begins with a ':' then it's the name of a set of symbols that are imported together. For example, in CGI.pm ':html2' imports all of the HTML 2.0 shortcut functions and ':cgi' imports all of the functions that deal with the CGI protocol. The list of these sets and what they contain is in the documentation.

Notice two points in that documentation. Firstly the section is called "Using the Function-Oriented Interface". As these sets import sets of symbols into your symbol table, they are only useful if you are using CGI.pm's function-oriented interface. From all of the code you have shown us, it is obvious that you are using CGI.pm's OO interface. Therefore these tags are of no use to you at all and you shouldn't use them. Secondly, the definition of the ':standard' set says:

Import "standard" features, 'html2', 'html3', 'html4', 'form' and 'cgi'.

Therefore if you import the ':standard' set, it includes the ':html2' set and there is no reason to import the ':html2' set again.

All of this means that the parameters on your line:

use CGI qw/:standard :html2/;

are a) overcomplex and b) completely unnecessary. You don't need them.

You do, however, want the '-no_xhtml' pragma. So you need to have that in your use statement. It should look like this:

use CGI qw/-no_xhtml/;

It's worth noting that if you were using the function-oriented interface then you could mix both import tags and pragmas in the same statement like this:

use CGI qw/-no_xhtml :standard/;

All of this is in the documentation and although you think you're far too busy to read the documentation, I would urge you to make time to do so - as it will make you a better programmer.

Replies are listed 'Best First'.
Re^6: XML tags using perl CGI
by pmcaveman (Novice) on Feb 06, 2007 at 13:48 UTC
    So, what is the difference bewteen :
    use CGI qw/:standard :html2/;
    and
    use CGI qw(:standard :html2);

    What does the qw do, and what is the difference between a : parameter, like :standard, and a - parameter, like -no_xhtml?

    Anyway, sorry for my ignorance, and the help/tutorial is greatly appreciated.

    BTW, for using this website, is it possible to see all of the items for a single node under one tree? What does the + and - do when reading through a node?
      What does the qw do

      qw// is the "quote words" operator. It's a quick way to build a list from whitespace separated string. It's documented in the section on Quote and Quote-like Operators in perlop. Like all of the quote-like operators you can use any delimiter that makes sense for you, so qw/:standard :html2/ is exactly the same as qw(:standard :html2).

      what is the difference between a : parameter, like :standard, and a - parameter, like -no_xhtml?

      There are no fixed rules for how these parameters work - only conventions. One convention is that a module should use Exporter to control its exports (the module's exports are your programs imports). Exporter defines the ':foo' syntax for groups of symbols that are exported together. CGI.pm doesn't use Exporter to manage its exports, but it does stick to the ':foo' syntax to designate export groups. The '-foo' syntax for other parameters is (as far as I know) something that was invented by the author of CGI.pm, but these parameters are "options" that control how CGI.pm works for the '-foo' syntax was almost certainly chosen to mirror the common syntax of options to command line options. It also mirrors the syntax used to pass parameters to many CGI functions (e.g. start_html(-title => 'foo')).