Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Undefined subroutine CGI::Vars

 
 
Sherm Pendley
Guest
Posts: n/a
 
      08-01-2004
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
 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      08-01-2004
Mark wrote:

> 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.


Is that your *real* code?

I suspect that your real code might actually be calling Vars() like this:

my $params = Vars();

In that case, your problem might come from the dual sets of 'use'
statements. A module that has already been 'use'd won't be reloaded if
another 'use' is encountered, so the second - which imports the function
you want to use - wouldn't have any effect.

So you might try one of two things. Either make sure that your real code
does call Vars() as a method, like the code you posted here does. Or,
import both groups of functions with a single use statement, like this:

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

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
 
 
 
Mark
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:
>
> >> $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.
>


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


 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      08-01-2004
Perusion Hostmaster wrote:

> The docs say that you should "use CGI qw/:cgi-lib/" if you want
> to import Vars as a function


That's true.

> -- not if you want to use it as an object method.


That's not. If you call a method, it shouldn't matter if it's imported
or not - importing it is unnecessary, but doing so shouldn't trigger an
"Unknown subroutine" error like the one Mark posted.

On the other paw, unnecessary imports *should* be avoided for the sake
of style and clarity. Think of the poor schmuck who'll have to alter
this code in two years - especially if that poor schmuck might be
yourself.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      08-01-2004
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
 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      08-02-2004
They use Perl 5.6.1 so I guess that's why.

Mark

"Sherm Pendley" <> wrote in message
news:T_udnfJr9IJmLpHcRVn-...
> 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



 
Reply With Quote
 
Mark
Guest
Posts: n/a
 
      08-02-2004

"Sherm Pendley" <> wrote in message
news:78Wdnda4-8L-MJHcRVn-...
> Mark wrote:
>
> > 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.

>
> Is that your *real* code?


*Real* code? Are you suggesting I would post *fake* code?! Would I do such a
thing?
Seriously though, it is just a straight copy and paste.

>
> I suspect that your real code might actually be calling Vars() like this:
>
> my $params = Vars();
>
> In that case, your problem might come from the dual sets of 'use'
> statements. A module that has already been 'use'd won't be reloaded if
> another 'use' is encountered, so the second - which imports the function
> you want to use - wouldn't have any effect.
>
> So you might try one of two things. Either make sure that your real code
> does call Vars() as a method, like the code you posted here does. Or,
> import both groups of functions with a single use statement, like this:
>
> use CGI qw(:standard :cgi-lib);


What I did do is tried every permutation of code I could think of based on
the various articles I read to see where the error could have lain including
what you have given me above but as every permutation brought up the same
errors I did not know where the error lay. The code I posted happened to be
where I was at at the time of posting. (I also tried both OO and method).Yes
I had read about the above in perldoc too but no wonder I was confused - it
was never going to work anyway (see previous post) CGI::Vars was definitely
not installed on the server.

Anyway no need for more replies to this topic for my benefit at least anyway
as had the Vars function been installed on the server my initial code would
have worked right from the start - the perldoc explained it well enough for
me. It was only through messing with the code to try to find the cause of
the error that led to the confused mess of my previous posts. But, of
course, if you still have matters to settle with the other posters in this
thread I will be happily lurking in the background taking notes...

Mark

>
> sherm--
>
> --
> Cocoa programming in Perl: http://camelbones.sourceforge.net
> Hire me! My resume: http://www.dot-app.org



 
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