Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

CGI.pm
Lo all,

Very quickly....

#!/usr/bin/perl
use CGI;
use strict;
use warnings;

my $Query = new CGI;
if (!$Query->request_method() eq "POST") {
exit;
}

Using a GET / HEAD method, the IF statement never executes.  I am trying to
verify the user agent, but the above is just for my test - which is failing.

Anyone got some clues?

--
Chris.

I love deadlines. I especially love the whooshing sound they make as they
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'


Report this thread to moderator Post Follow-up to this message
Old Post
Chris Knipe
03-29-05 08:56 PM


RE: CGI.pm

> -----Original Message-----
> From: Chris Knipe [mailto:savage@savage.za.org]
> Sent: Tuesday, March 29, 2005 10:45 AM
> To: beginners@perl.org
> Subject: CGI.pm
>
> Lo all,
>
> Very quickly....
>
> #!/usr/bin/perl
> use CGI;
> use strict;
> use warnings;
>
> my $Query = new CGI;
> if (!$Query->request_method() eq "POST") {
>   exit;
> }
>
> Using a GET / HEAD method, the IF statement never executes.
> I am trying to verify the user agent, but the above is just
> for my test - which is failing.
>
> Anyone got some clues?
>
> --
> Chris.
>
> I love deadlines. I especially love the whooshing sound they
> make as they fly by..." - Douglas Adams, 'Hitchhiker's Guide
> to the Galaxy'
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>

Untested:

if ($query->request_method() =~ m/^post$/i)	{
do something;
}

Chris

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Heiland
03-29-05 08:56 PM


Re: CGI.pm
Strange indeed.

For further debuging, I did:

print $ENV{REQUEST_METHOD};

This, as expected, returns POST.

print $Query->request-method();

NULL value.

if ($ENV{REQUEST_METHOD} eq "POST")

Does not match....

Another one of those ARGH moments, or am I doing something silly?

--
Chris.



--
Chris.

I love deadlines. I especially love the whooshing sound they make as they
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

----- Original Message -----
From: "Chris Heiland" <CHeiland@uwb.edu>
To: <beginners@perl.org>
Sent: Tuesday, March 29, 2005 8:52 PM
Subject: RE: CGI.pm


>
> 
>
> Untested:
>
> if ($query->request_method() =~ m/^post$/i) {
> do something;
> }
>
> Chris
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Chris Knipe
03-30-05 01:56 AM


Re: CGI.pm
On Tue, 29 Mar 2005, Chris Knipe wrote:

> if (!$Query->request_method() eq "POST") {
>  exit;
> }
>
> Using a GET / HEAD method, the IF statement never executes.

Nor would it -- the exclamation point isn't in the right place.

This statement is saying "if not-$query->request_method() equals POST",
but "not-$query..." makes no sense.

But an exclamation point is the wrong approach here. If you want to say
that $foo should not equal $bar, use the "not equal" condition -- 'ne':

if $Query->request_method() ne "POST" {
exit;
}

That should do what you want.


--
Chris Devers

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
03-30-05 01:56 AM


Re: CGI.pm
Ok, sorry.

This now, does not make sense AT ALL!!!!

useing == (which is wrong), matches.
useing eq (which is right?) never matches...

Surely, if I match $ENV{REQUEST_METHOD} I am matching a string value....
Why, oh why dear mighty will == match (and give me a warning), and eq never
matches....

--
Chris.

I love deadlines. I especially love the whooshing sound they make as they
fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'

----- Original Message -----
From: "Chris Knipe" <savage@savage.za.org>
To: <beginners@perl.org>
Sent: Tuesday, March 29, 2005 9:00 PM
Subject: Re: CGI.pm


> Strange indeed.
>
> For further debuging, I did:
>
> print $ENV{REQUEST_METHOD};
>
> This, as expected, returns POST.
>
> print $Query->request-method();
>
> NULL value.
>
> if ($ENV{REQUEST_METHOD} eq "POST")
>
> Does not match....
>
> Another one of those ARGH moments, or am I doing something silly?
>
> --
> Chris.
>
>
>
> --
> Chris.
>
> I love deadlines. I especially love the whooshing sound they make as they
> fly by..." - Douglas Adams, 'Hitchhiker's Guide to the Galaxy'
>
> ----- Original Message -----
> From: "Chris Heiland" <CHeiland@uwb.edu>
> To: <beginners@perl.org>
> Sent: Tuesday, March 29, 2005 8:52 PM
> Subject: RE: CGI.pm
>
> 
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>


Report this thread to moderator Post Follow-up to this message
Old Post
Chris Knipe
03-30-05 01:56 AM


RE: CGI.pm

> -----Original Message-----
> From: Chris Knipe [mailto:savage@savage.za.org]
> Sent: Tuesday, March 29, 2005 11:01 AM
> To: beginners@perl.org
> Subject: Re: CGI.pm
>
> Strange indeed.
>
> For further debuging, I did:
>
> print $ENV{REQUEST_METHOD};
>
> This, as expected, returns POST.
>
> print $Query->request-method();
>
> NULL value.
>
> if ($ENV{REQUEST_METHOD} eq "POST")
>
> Does not match....
>
> Another one of those ARGH moments, or am I doing something silly?
>
> --
> Chris.
>
[snip] 
[snip] 

If you are just testing to see if they submitted the form then:

if ($ENV{'REQUEST_METHOD'} =~ m/^post$/i)	{
do something;
}

If you are trying to see what is in the variables then I suggest
Data::Dumper:
perldoc Data::Dumper

Then just do a dump of what you think should contain something and it will
show you the contents.  But then again it ultimately matters by what you
want to do with 'verify the user agent'.

Chris

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Heiland
03-30-05 01:56 AM


Re: CGI.pm
DOH!

Something Silly(tm)

Thanks ;)

----- Original Message -----
From: "Chris Devers" <cdevers@pobox.com>
To: "Chris Knipe" <savage@savage.za.org>
Cc: "Perl Beginners List" <beginners@perl.org>
Sent: Tuesday, March 29, 2005 9:07 PM
Subject: Re: CGI.pm


> On Tue, 29 Mar 2005, Chris Knipe wrote:
> 
>
> Nor would it -- the exclamation point isn't in the right place.
>
> This statement is saying "if not-$query->request_method() equals POST",
> but "not-$query..." makes no sense.
>
> But an exclamation point is the wrong approach here. If you want to say
> that $foo should not equal $bar, use the "not equal" condition -- 'ne':
>
>    if $Query->request_method() ne "POST" {
>        exit;
>    }
>
> That should do what you want.
>
>
> --
> Chris Devers
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Knipe
03-30-05 01:56 AM


RE: CGI.pm
On Tue, 29 Mar 2005, Chris Heiland wrote:

> Untested:
>
> if ($query->request_method() =~ m/^post$/i)	{
> 	do something;
> }

If you're matching against a known, fixed pattern, the string comparison
operators will almost always be faster and clearer than the equivalent
regex. In this case, the method is always going to be one of POST, GET,
HEAD, etc, so it's much better to use the string comparison operator.

if $query->request_method() eq 'POST' {
do_something();
}

(And of course, don't use the numerical comparison operators, because
we're dealing here with strings, not numbers.)




--
Chris Devers

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
03-30-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:53 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.