Syntax error in mod_perl but not in shell command

Syntax error in mod_perl but not in shell command

am 29.05.2008 08:50:25 von Keenlearner

Hello, I am running this code

print "Content-type: text/html\n\n";

use Switch;
$t =1;

switch ($t) {
case 1 { print "number 1\n"; }
}

I have not problem running in shell command
william@william-pc:/var/www/modperl$ perl test.pl
Content-type: text/html

number 1

But when I ran in mod_perl , I got error
[Thu May 29 14:48:16 2008] [error] syntax error at
/var/www/modperl/test.pl line 6, near ") {"\nNumber found where
operator expected at /var/www/modperl/test.pl line 7, near "case
1"\nsyntax error at /var/www/modperl/test.pl line 8, near "}\n}"\n


Thanks

Re: Syntax error in mod_perl but not in shell command

am 29.05.2008 18:03:53 von mcapone

I can reproduce this, exactly as he says below. Some kind of
incompatibility between mod_perl and the Switch module?

william wrote:

>Hello, I am running this code
>
>print "Content-type: text/html\n\n";
>
>use Switch;
>$t =1;
>
>switch ($t) {
> case 1 { print "number 1\n"; }
>}
>
>I have not problem running in shell command
>william@william-pc:/var/www/modperl$ perl test.pl
>Content-type: text/html
>
>number 1
>
>But when I ran in mod_perl , I got error
>[Thu May 29 14:48:16 2008] [error] syntax error at
>/var/www/modperl/test.pl line 6, near ") {"\nNumber found where
>operator expected at /var/www/modperl/test.pl line 7, near "case
>1"\nsyntax error at /var/www/modperl/test.pl line 8, near "}\n}"\n
>
>
>Thanks
>
>
>

--

---------------------------------------------------------
CCCCC CableWholesale.com, Inc.
_ CC CC P.O. Box 11775
| CC ------------------ m Pleasanton, CA 94588
| CC 888-212-8295 o
|_ CC ================== c 1-888-212-8295 Phone
CC CC CableWholesale . 1-925-455-0808 Fax
CCCCC www.cablewholesale.com
---------------------------------------------------------

Re: Syntax error in mod_perl but not in shell command

am 29.05.2008 18:08:48 von mpeters

Michael A. Capone wrote:
> I can reproduce this, exactly as he says below. Some kind of
> incompatibility between mod_perl and the Switch module?

Switch is a source filter. source filters == evil. I've heard all kinds of
horror stories about using them under mod_perl.

If you really need that kind of a statement use Perl 5.10's given/when. Much
more powerful. Switch is really just syntax sugar for if/elseif/else.

--
Michael Peters
Plus Three, LP

Re: Syntax error in mod_perl but not in shell command

am 29.05.2008 18:15:11 von Heiko Jansen

As far as I understand it, mod_perl will eval{} the code it's going to
run and in the paragraph "Limitations" on
http://search.cpan.org/~rgarcia/Switch-2.13/Switch.pm
we're told that "Due to the way source filters work in Perl, you can't
use Switch inside an string eval.".

heiko

Re: Syntax error in mod_perl but not in shell command

am 29.05.2008 19:27:56 von Keenlearner

On 5/30/08, Heiko Jansen wrote:
> As far as I understand it, mod_perl will eval{} the code it's going to
> run and in the paragraph "Limitations" on
> http://search.cpan.org/~rgarcia/Switch-2.13/Switch.pm
> we're told that "Due to the way source filters work in Perl, you can't
> use Switch inside an string eval.".
>
>
> heiko
>
>


Yeah, I love mod_perl but it's a little disappointing, because I guess
I would not longer assume that whatever that I can run in CGI, I can
run in mod_perl too. I have upgraded my perl to 5.10 now. Thanks.