Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > grep causes internal server error

Reply
Thread Tools

grep causes internal server error

 
 
davidzxz@gmail.com
Guest
Posts: n/a
 
      04-23-2007
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

 
Reply With Quote
 
 
 
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      04-23-2007
On Apr 23, 2:14 pm, (E-Mail Removed) wrote:

> @photofiles = grep ($_ ~ /^photo\d+\.jpg$/, @photofiles);


Did you mean =~ or !~ (instead of plain '~" for your comparison
operator)?

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)



 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      04-23-2007
On Apr 23, 5:14 pm, (E-Mail Removed) wrote:
> 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

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      04-24-2007
Paul Lalli wrote:
> On Apr 23, 5:14 pm, (E-Mail Removed) wrote:
>> 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.


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


 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      04-24-2007
Jürgen Exner wrote:
> Paul Lalli wrote:
>> On Apr 23, 5:14 pm, (E-Mail Removed) wrote:
>>> 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.

>
> 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
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
 
Reply With Quote
 
Heinrich Mislik
Guest
Posts: n/a
 
      04-24-2007
In article <JeeXh.16810$VF5.15637@edtnps82>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...

>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

 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      04-24-2007
Heinrich Mislik wrote:
> In article <JeeXh.16810$VF5.15637@edtnps82>, (E-Mail Removed) says...
>
>>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.


$ 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
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
 
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
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
837. Unable to see internal web server from internal server. eric the brave Cisco 0 03-05-2006 01:52 PM
Post file to ASP.NET causes HTTP 500: Internal Server Error stefan ASP .Net Web Services 0 03-21-2005 11:38 AM
Internal Client Accessing Internal Server Via Public IP Address GeekMarine1972 Cisco 1 01-15-2005 02:49 AM
(Perl) FILE/IO and grep causes 100% CPU mark@gowans.org Perl Misc 2 11-27-2004 08:14 AM



Advertisments