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

G

Guy

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
 
E

Eric Schwartz

Guy said:
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
 
M

Matt Garrish

Guy said:
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
 
T

Tintin

Guy said:
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.
 
M

Malcolm Dew-Jones

Guy ([email protected]) 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top