use CGI; vs use CGI qw(:standard);

Discussion in 'Perl Misc' started by Guy, Dec 11, 2003.

  1. Guy

    Guy Guest

    I used to always start my Perl scripts with the following:

    #!/usr/bin/perl
    use CGI qw:)standard);

    But in my search to create a script that would upload a file upon submission
    from a web site, I found that these scripts begin with:

    #!/usr/bin/perl
    use CGI;

    And then they continue with code like:

    $query=new CGI;
    $fname=$query->param("document");
    $fhandle=$query->upload("document");

    Is this a new flavor of Perl, or is it just a new library...?

    Will a Perl script written with use CGI qw:)standard); work if
    this one line is changed to use CGI;

    In other words, does use CGI; do everything that use CGI
    qw:)standard:); does and then some?

    Thanks for all
    G.Doucet
    Guy, Dec 11, 2003
    #1
    1. Advertising

  2. "Guy" <> writes:
    > I used to always start my Perl scripts with the following:
    >
    > #!/usr/bin/perl
    > use CGI qw:)standard);


    Don't forget

    use warnings;
    use strict;

    > But in my search to create a script that would upload a file upon submission
    > from a web site, I found that these scripts begin with:
    >
    > #!/usr/bin/perl
    > use CGI;
    >
    > And then they continue with code like:
    >
    > $query=new CGI;
    > $fname=$query->param("document");
    > $fhandle=$query->upload("document");
    >
    > Is this a new flavor of Perl, or is it just a new library...?


    Neither; it's just another way to use the same library you're using
    now. When you call param(), upload(), or whatever, CGI.pm is creating
    a "query object" behind the scenes, and passing those methods to it.
    The form you're asking about just does that explicitly.

    If you read the CGI.pm docs, you'll see how to use both forms. If you
    want to learn more about object-oriented Perl, read 'perldoc perltoot'.

    -=Eric
    --
    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
    Eric Schwartz, Dec 11, 2003
    #2
    1. Advertising

  3. Guy

    Matt Garrish Guest

    "Guy" <> wrote in message
    news:tU6Cb.9864$...
    > I used to always start my Perl scripts with the following:
    >
    > #!/usr/bin/perl
    > use CGI qw:)standard);
    >
    > But in my search to create a script that would upload a file upon

    submission
    > from a web site, I found that these scripts begin with:
    >
    > #!/usr/bin/perl
    > use CGI;
    >
    > And then they continue with code like:
    >
    > $query=new CGI;
    > $fname=$query->param("document");
    > $fhandle=$query->upload("document");
    >
    > Is this a new flavor of Perl, or is it just a new library...?
    >


    It's neither. It's just a different way of accessing the functions in
    CGI.pm. When you add qw:)standard), you are asking Perl to import than
    "standard" functions for the module. If you don't import them, you could
    still create a new CGI object ($query) to access the functions. Or if you
    don't like either method, you could qw(param), for example, and just import
    the specific functions you need (I use param as an example because its one
    of the only functions I ever use from the module).

    > Will a Perl script written with use CGI qw:)standard); work if
    > this one line is changed to use CGI;
    >


    Unlikely. You'd have to import the functions you're using or rewrite the
    script using a CGI object as per above

    Matt
    Matt Garrish, Dec 11, 2003
    #3
  4. Guy

    Tintin Guest

    "Guy" <> wrote in message
    news:tU6Cb.9864$...
    > I used to always start my Perl scripts with the following:
    >
    > #!/usr/bin/perl
    > use CGI qw:)standard);
    >
    > But in my search to create a script that would upload a file upon

    submission
    > from a web site, I found that these scripts begin with:
    >
    > #!/usr/bin/perl
    > use CGI;
    >
    > And then they continue with code like:
    >
    > $query=new CGI;
    > $fname=$query->param("document");
    > $fhandle=$query->upload("document");
    >
    > Is this a new flavor of Perl, or is it just a new library...?


    Neither. It's all fully explained in the CGI module documentation which it
    appears you haven't read.

    >
    > Will a Perl script written with use CGI qw:)standard); work if
    > this one line is changed to use CGI;


    No.

    >
    > In other words, does use CGI; do everything that use CGI
    > qw:)standard:); does and then some?


    Mostly. See documentation as previously mentioned.
    Tintin, Dec 11, 2003
    #4
  5. Guy () wrote:
    : I used to always start my Perl scripts with the following:

    : #!/usr/bin/perl
    : use CGI qw:)standard);

    : But in my search to create a script that would upload a file upon submission
    : from a web site, I found that these scripts begin with:

    : #!/usr/bin/perl
    : use CGI;

    : And then they continue with code like:

    : $query=new CGI;
    : $fname=$query->param("document");
    : $fhandle=$query->upload("document");

    : Is this a new flavor of Perl, or is it just a new library...?

    : Will a Perl script written with use CGI qw:)standard); work if
    : this one line is changed to use CGI;

    : In other words, does use CGI; do everything that use CGI
    : qw:)standard:); does and then some?

    : Thanks for all
    : G.Doucet


    perldoc CGI

    will explain it all.

    The CGI library (there is just one if it) has supported both access
    techniques for many years, none of the above is at all new.
    Malcolm Dew-Jones, Dec 11, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve.leach

    How standard is the standard library?

    steve.leach, Apr 18, 2005, in forum: Python
    Replies:
    1
    Views:
    388
    Christos TZOTZIOY Georgiou
    Apr 18, 2005
  2. funkyj
    Replies:
    5
    Views:
    1,122
    funkyj
    Jan 20, 2006
  3. Replies:
    5
    Views:
    859
  4. Sriram Srinivasan
    Replies:
    13
    Views:
    561
    Benjamin Kaplan
    Nov 12, 2009
  5. javatiger

    use CGI qw(:standard) ???

    javatiger, Sep 12, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    105
    krakle
    Sep 14, 2004
Loading...

Share This Page