Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > use CGI; vs use CGI qw(:standard);

Reply
Thread Tools

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

 
 
Guy
Guest
Posts: n/a
 
      12-11-2003
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



 
Reply With Quote
 
 
 
 
Eric Schwartz
Guest
Posts: n/a
 
      12-11-2003
"Guy" <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      12-11-2003

"Guy" <(E-Mail Removed)> wrote in message
news:tU6Cb.9864$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      12-11-2003

"Guy" <(E-Mail Removed)> wrote in message
news:tU6Cb.9864$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Malcolm Dew-Jones
Guest
Posts: n/a
 
      12-11-2003
Guy ((E-Mail Removed)) 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(CGI-Target)Could not connect to CGI-Proxy John Smith Java 0 05-15-2006 09:21 PM
Re: [OT] Re: "use CGI " hangs "CGI time out " Alfred Z. Newmane C Programming 13 06-24-2005 03:26 PM
"use CGI " hangs "CGI time out " GMI Perl Misc 25 06-24-2005 01:23 PM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM
Re: CGI Perl "use CGI" statement fail Jürgen Exner Perl 0 07-31-2003 02:00 PM



Advertisments