Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Undefined subroutine CGI::Vars

Reply
Thread Tools

Undefined subroutine CGI::Vars

 
 
Mark
Guest
Posts: n/a
 
      07-26-2004
I want to store my request variables as a hash and have the code:

use CGI qw(:standard);
use CGI qw(:cgi-lib);
#during development, put Perl errors to the browser
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $q = new CGI;
my $params = $q->Vars();

but the server is giving me an error message:

Undefined subroutine CGI::Vars

but I'm not sure why.

Thanks
Mark


 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      07-26-2004
Mark <> wrote:

> use CGI qw(:standard);
> use CGI qw(:cgi-lib);


[snip]

> my $q = new CGI;



Object oriented interfaces do not need to import anything into
your name space, so don't import anything into your namespace.


use CGI;


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
 
krakle
Guest
Posts: n/a
 
      07-26-2004
"Mark" <> wrote in message news:<7d8Nc.19215$. uk>...
> I want to store my request variables as a hash and have the code:
>
> use CGI qw(:standard);
> use CGI qw(:cgi-lib);
> #during development, put Perl errors to the browser
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
> my $q = new CGI;
> my $params = $q->Vars();
>
> but the server is giving me an error message:
>
> Undefined subroutine CGI::Vars
>


I see lot's of problems.. The format your using CGI.pm is OO yet you
call it as function. You are also calling cgi-lib. And you are using a
scalar to stora Vars when it should be a hash to collect all. Try:

#!/usr/bin/perl -Tw
use strict;
use CGI; # Object Oriented Interface

my $q = new CGI;
my %params = $q->Vars; # Now you can use $params{name} for value of
name
 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      07-26-2004

"Tad McClellan" wrote...
> Mark wrote:
>


[snip]

>
> Object oriented interfaces do not need to import anything into
> your name space, so don't import anything into your namespace.
>
> use CGI;



Thanks. I took out the two imports so the code is now:

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $q = new CGI;
my $grandtotal= sprintf("%.2f", ($q->param('grandtotal')));
$params = $q->Vars;

now I get the error.

Execution /orderform.cgi aborted due to compilation errors.

If I replace the last line with

my $params = $q->Vars;

then I get as previously:

Undefined subroutine CGI::Vars

so I am not sure which is in error.

Perhaps my web host does not have the right library installed? They list the
following CGI modules as installed:

CGI::Apache
CGI::Carp
CGI::Cookie
CGI::Fast
CGI:retty
CGI:ush
CGI::Switch
CGI::Util

In order to successfully log orders made from my shopping cart script I have
to be able to use the (unknown amount of) POST variables in hidden form
fields. I can't see an easy way of doing this unless I can assign them to a
hash variable. Any suggestions?

Thanks
Mark



 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      07-27-2004

"Mark" <> wrote in message
news:eEgNc.24695$. uk...
> Thanks. I took out the two imports so the code is now:
>
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
> my $q = new CGI;
> my $grandtotal= sprintf("%.2f", ($q->param('grandtotal')));
> $params = $q->Vars;
>
> now I get the error.
>
> Execution /orderform.cgi aborted due to compilation errors.


Due to you not declaring $params

>
> If I replace the last line with
>
> my $params = $q->Vars;
>
> then I get as previously:
>
> Undefined subroutine CGI::Vars
>
> so I am not sure which is in error.


You must have a pretty old version of Perl/CGI module installed on your
webserver.



 
Reply With Quote
 
krakle
Guest
Posts: n/a
 
      07-28-2004
"Mark" <> wrote in message news:<eEgNc.24695$ .uk>...
> "Tad McClellan" wrote...
> > Mark wrote:
> >

>
> [snip]
>
> >
> > Object oriented interfaces do not need to import anything into
> > your name space, so don't import anything into your namespace.
> >
> > use CGI;

>
>
> Thanks. I took out the two imports so the code is now:
>
> use CGI;
> use CGI::Carp qw(fatalsToBrowser);
> use strict;
> my $q = new CGI;
> my $grandtotal= sprintf("%.2f", ($q->param('grandtotal')));
> $params = $q->Vars;


my %params = $q->Vars;

>
> now I get the error.


Read my other reply to this. Geesh.
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      07-29-2004
krakle wrote:

> "Mark" <> wrote in message news:<eEgNc.24695$ .uk>...
>
>> $params = $q->Vars;

>
>
> my %params = $q->Vars;


Calling Vars() in scalar context is valid, and returns a tied hash
reference.

Unlike the hash you get when you call Vars() in array context, the hash
reference you get by calling it in scalar context is not read-only. It
can also be used to set parameters for output, which is used in self-
referential CGIs that include forms and/or links back to themselves in
the HTML they output.

> Read my other reply to this. Geesh.


Read 'perldoc CGI'. Geesh.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
krakle
Guest
Posts: n/a
 
      07-30-2004
Sherm Pendley <> wrote in message news:<J62dnYlelOguEJXcRVn->...>
> Read 'perldoc CGI'. Geesh.
>
> sherm--


He wanted to know why it didn't work. I showed him a working example.
Which was tested. Being that I use it in most of my scripts... Then he
complained his script still didn't work... I pointed out exactly what
he did wrong... Using OO while CGI is called as function.
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      07-30-2004
krakle wrote:

> I pointed out exactly what
> he did wrong... Using OO while CGI is called as function.


In the post I replied to, the only thing you "pointed out" was this:

>> $params = $q->Vars;

>
>
> my %params = $q->Vars;
>


The "error" that you're "correcting" above is not an error, nor does it
have anything to do with methods vs. functions. Calling Vars() in scalar
context is allowed, regardless of whether you call it as a method or as
a function.

The addition of "my" above *is* good advice - which is why I did not
criticize it in my reply.

You also said:

> Read my other reply to this. Geesh.


.... and in that other reply:

> And you are using a
> scalar to stora Vars when it should be a hash to collect all.


That is false, and repetition won't make it true. Using a scalar to get
a hashref is valid, supported, useful, and - most importantly - documented.

Also from your earlier reply:

>>my $q = new CGI;
>>my $params = $q->Vars();


> I see lot's of problems.. The format your using CGI.pm is OO yet you
> call it as function.


You're wrong here too. Mark is *not* calling Vars as a function in the
code he posted. He is creating a query object $q, and calling $q->Vars()
as an instance method.

Your advice here is pointless - importing functions into the local name
space won't prevent OO the methods from working. There's no reason to do
so if you intend to use OO methods, that's true, but it won't cause the
type of error he's getting.

So drop the snide attitude and whiny "Geesh" comments please. If you
want people to follow your advice, post some advice worth following.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
krakle
Guest
Posts: n/a
 
      08-01-2004
Sherm Pendley <> wrote in message news:<sdOdndrlQP5aI5fcRVn->...
> krakle wrote:
>
> > I pointed out exactly what
> > he did wrong... Using OO while CGI is called as function.

>
> In the post I replied to, the only thing you "pointed out" was this:


Since when do you reply to a snipet of post without reading the whole
thread?

>
> >> $params = $q->Vars;

> >
> >
> > my %params = $q->Vars;
> >

>
> The "error" that you're "correcting" above is not an error, nor does it
> have anything to do with methods vs. functions.


Sure it does. 1 he called CGI.pm as a method. However he is using
OO... I never said it was an error.. I simply stated a snipet that did
infact WORK and accomplish exactly what he was doing...

>
> The addition of "my" above *is* good advice - which is why I did not
> criticize it in my reply.


Good advice. Bad advice. No advice. Doesn't it all get criticized on
usenet? What's your point, lad?

>
> You also said:
>
> > Read my other reply to this. Geesh.

>
> ... and in that other reply:
>
> > And you are using a
> > scalar to stora Vars when it should be a hash to collect all.

>
> That is false, and repetition won't make it true. Using a scalar to get
> a hashref is valid, supported, useful, and - most importantly - documented.


Which code works? Mine or his? Mind. Does it accomplish his goal? Yes.

>
> Also from your earlier reply:
>
> >>my $q = new CGI;
> >>my $params = $q->Vars();

>
> > I see lot's of problems.. The format your using CGI.pm is OO yet you
> > call it as function.

>
> You're wrong here too. Mark is *not* calling Vars as a function in the
> code he posted. He is creating a query object $q, and calling $q->Vars()
> as an instance method.


He wanted help, correct? I gave him help and a working example that
accomplishes exactly what he is trying to do. If you can get that much
on usenet you are a lucky duck... Most people just criticize peoples
postings.... *snickers*.. Having fun?

>
> Your advice here is pointless


And I stop your post here. You summed it up... My working code is
worthless to the guy whose code doesn't work. Don't you love usenet
advice? Round 3.
 
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
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
Undefined subroutine CGI::Vars Mark Perl 0 07-26-2004 02:13 PM
intermittent "Undefined subroutine" with mod_perl Moulin Kluge Perl Misc 2 01-27-2004 09:54 PM
testing for 'undefined subroutine' Torsten Mangner Perl Misc 3 11-05-2003 02:23 AM
"Undefined subroutine" error (but it's defined, I think?) valerian2@hotpop.com Perl Misc 4 08-12-2003 10:26 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57