grep causes internal server error

D

davidzxz

Hi

I have trouble with the grep command.
My script has these lines:

opendir(DIR, "photodir") || do {&open_failed;};
@photofiles = readdir(DIR);
closedir(DIR);
@photofiles = grep ($_ !~ /^\.\.?$/, @photofiles);
@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);

The last line causes an internal server error, but why?
The line before that works fine though...

Appreciate your time!
/David - Sweden
 
P

Paul Lalli

Hi

I have trouble with the grep command.
My script has these lines:

opendir(DIR, "photodir") || do {&open_failed;};
@photofiles = readdir(DIR);
closedir(DIR);
@photofiles = grep ($_ !~ /^\.\.?$/, @photofiles);
@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);

The last line causes an internal server error, but why?

Probably because it's a syntax error. If for some reason you don't
have access to your CGI server's error logs, you can put this line
into your CGI script to have the syntax errors show up in the browser:

use CGI::Carp 'fatalsToBrowser';
The line before that works fine though...

The line before it isn't a syntax error. The ~ operator makes no
sense there. I'd have to guess you meant to use either the =~ or !~
operator there.

Paul Lalli
 
J

Jürgen Exner

Paul said:
Probably because it's a syntax error.

Actually no (with t.pl containing exactly the lines above):
C:\tmp>perl -c t.pl
t.pl syntax OK
The ~ operator makes no sense there.

That on the other hand seems to be quite true.

jue
 
J

John W. Krahn

Jürgen Exner said:
Actually no (with t.pl containing exactly the lines above):
C:\tmp>perl -c t.pl
t.pl syntax OK

It *should* be a syntax error:

$ perl -MO=Deparse -e'$_ ~ /^photo\d+\.jpg$/'
syntax error at -e line 1, near "$_ ~"
-e had compilation errors.


But apparently grep is interpreting the first scalar as a code block?

$ perl -MO=Deparse -e'@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles)'
@photofiles = grep($_, ~/^photo\d+\.jpg$/, @photofiles);
-e syntax OK



John
 
H

Heinrich Mislik

It *should* be a syntax error:

$ perl -MO=Deparse -e'$_ ~ /^photo\d+\.jpg$/'
syntax error at -e line 1, near "$_ ~"
-e had compilation errors.


But apparently grep is interpreting the first scalar as a code block?

$ perl -MO=Deparse -e'@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles)'
@photofiles = grep($_, ~/^photo\d+\.jpg$/, @photofiles);
-e syntax OK

What version is this. When I try it, I get:

# perl -MO=Deparse -e'@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles)'
panic: ck_grep at -e line 1.

# perl -v

This is perl, v5.8.7 built for cygwin-thread-multi-64int
(with 1 registered patch, see perl -V for more detail)

Looks like a bug to me.

Cheers

Heinrich
 
J

John W. Krahn

Heinrich said:
What version is this. When I try it, I get:

# perl -MO=Deparse -e'@photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles)'
panic: ck_grep at -e line 1.

# perl -v

This is perl, v5.8.7 built for cygwin-thread-multi-64int
(with 1 registered patch, see perl -V for more detail)

Looks like a bug to me.

$ perl -v

This is perl, v5.8.6 built for i586-linux-thread-multi
(with 1 registered patch, see perl -V for more detail)




John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top