Code Comments
Programming Forum and web based access to our favorite programming groups.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'
Post Follow-up to this message
> -----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
Post Follow-up to this messageStrange 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>
>
>
>
Post Follow-up to this messageOn 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
Post Follow-up to this messageOk, 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>
>
>
Post Follow-up to this message
> -----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
Post Follow-up to this messageDOH!
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>
>
>
>
Post Follow-up to this messageOn 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.