Home > Archive > PERL CGI Beginners > August 2004 > Re: Undefined subroutine CGI::Vars
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Undefined subroutine CGI::Vars
|
|
|
|
"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::Pretty
CGI::Push
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
| |
| Tintin 2004-07-28, 8:55 pm |
|
"Mark" <noonehere@fakoaddresso.como> wrote in message
news:eEgNc.24695$9J5.23024@fe2.news.blueyonder.co.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.
| |
| krakle 2004-07-28, 8:55 pm |
| "Mark" <noonehere@fakoaddresso.como> wrote in message news:<eEgNc.24695$9J5.23024@fe2.news.blueyonder.co.uk>...
> "Tad McClellan" wrote...
>
> [snip]
>
>
>
> 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.
| |
| Sherm Pendley 2004-07-29, 3:55 am |
| krakle wrote:
> "Mark" <noonehere@fakoaddresso.como> wrote in message news:<eEgNc.24695$9J5.23024@fe2.news.blueyonder.co.uk>...
>
>
>
> 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
| |
| krakle 2004-07-30, 8:55 pm |
| Sherm Pendley <spamtrap@dot-app.org> wrote in message news:<J62dnYlelOguEJXcRVn-ow@adelphia.com>...>
> 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.
| |
| Sherm Pendley 2004-07-30, 8:55 pm |
| 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:
>
>
> 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:
[color=darkred]
> 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
| |
| krakle 2004-08-01, 3:55 am |
| Sherm Pendley <spamtrap@dot-app.org> wrote in message news:<sdOdndrlQP5aI5fcRVn-rQ@adelphia.com>...
> krakle wrote:
>
>
> 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?
>
>
> 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:
>
>
> ... and in that other reply:
>
>
> 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:
>
>
>
> 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.
| |
| Sherm Pendley 2004-08-01, 8:55 am |
| krakle wrote:
> And I stop your post here. You summed it up...
Yes I did, and I'll do so again. You said that Vars() must be called in
list context, not scalar context. That is false, and the fact that it is
false is clearly documented in 'perldoc CGI' - a document you clearly
are not familiar with.
Further, you claimed that the OP called Vars() as a function, but the
code he posted read 'my $params = $q->Vars()' - clearly you don't know
the difference between a function and a method.
Mark asked for help. The error he received is "Undefined subroutine";
calling Vars() in scalar context will not produce that error, and
neither will calling Vars() as a method when it has also been imported
as a function.
Calling Vars() as a function *will* produce that error, if it has not
been imported as a function. But in the code Mark posted, it *is*
imported; not only that, it's called as a method. Doing both is wrong
only in terms of style - it won't cause an error.
You were wrong on at least one point, and overall your suggestions were
useless. Calling me rude won't change those facts.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
| |
|
|
"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:sdOdndrlQP5aI5fcRVn-rQ@adelphia.com...
> krakle wrote:
>
>
> In the post I replied to, the only thing you "pointed out" was this:
>
>
> 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.
>
Thanks for posting your advice which I have taken on board. Much of the
comments are moot now anyway as I emailed my host support who told me they
don't even have CGI::Vars installed anyway and won't do it (cheapskates!).
So all the code posted probably *should* work if that were not the case.
Hence the error message and my earlier suspicions were correct. I've opted
for changing the way I post my variables from the PHP server so I don't need
to use Vars just param().
[snip]
> So drop the snide attitude and whiny "Geesh" comments please.
I totally agree with you. I wish some people would try to remember what it
was like when *they* first started learning to code. It's this kind of
attitude that puts people off Usenet and totally negates any helpfulness of
the comments being offered. I tend to avoid people who post comments like
this as they often just need their egos massaged by being able to patronise
newbies. Thankfully there are people like yourself who are genuinely trying
to help people starting out in code and not just show-boating.
Thanks.
Mark
| |
| Sherm Pendley 2004-08-01, 8:55 am |
| Mark wrote:
> comments are moot now anyway as I emailed my host support who told me they
> don't even have CGI::Vars installed anyway and won't do it (cheapskates!).
Hmmm... That smells a little fishy. Vars() is part of the standard
CGI.pm module, and that module is standard with Perl 5.8.x and newer.
They might have a very old CGI.pm that doesn't have Vars() - in which
case they'd have to have an old Perl as well.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
| |
|
| They use Perl 5.6.1 so I guess that's why.
Mark
"Sherm Pendley" <spamtrap@dot-app.org> wrote in message
news:T_udnfJr9IJmLpHcRVn-hg@adelphia.com...
> Mark wrote:
>
they[color=darkred]
(cheapskates!).[color=darkred]
>
> Hmmm... That smells a little fishy. Vars() is part of the standard
> CGI.pm module, and that module is standard with Perl 5.8.x and newer.
> They might have a very old CGI.pm that doesn't have Vars() - in which
> case they'd have to have an old Perl as well.
>
> sherm--
>
> --
> Cocoa programming in Perl: http://camelbones.sourceforge.net
> Hire me! My resume: http://www.dot-app.org
|
|
|
|
|