grep causes internal server error

Discussion in 'Perl Misc' started by davidzxz@gmail.com, Apr 23, 2007.

  1. Guest

    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
     
    , Apr 23, 2007
    #1
    1. Advertising

  2. Guest

    On Apr 23, 2:14 pm, 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)
     
    , Apr 23, 2007
    #2
    1. Advertising

  3. Paul Lalli Guest

    On Apr 23, 5:14 pm, 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
     
    Paul Lalli, Apr 23, 2007
    #3
  4. Paul Lalli wrote:
    > On Apr 23, 5:14 pm, 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
     
    Jürgen Exner, Apr 24, 2007
    #4
  5. Jürgen Exner wrote:
    > Paul Lalli wrote:
    >> On Apr 23, 5:14 pm, 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
     
    John W. Krahn, Apr 24, 2007
    #5
  6. In article <JeeXh.16810$VF5.15637@edtnps82>, 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
     
    Heinrich Mislik, Apr 24, 2007
    #6
  7. Heinrich Mislik wrote:
    > In article <JeeXh.16810$VF5.15637@edtnps82>, 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
     
    John W. Krahn, Apr 24, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Bonds
    Replies:
    2
    Views:
    2,795
    Amaryllis
    Aug 3, 2004
  2. Replies:
    5
    Views:
    80,654
    cpdarkman
    Aug 26, 2009
  3. BobbyOwens
    Replies:
    0
    Views:
    4,681
    BobbyOwens
    Jan 23, 2009
  4. stefan
    Replies:
    0
    Views:
    179
    stefan
    Mar 21, 2005
  5. Replies:
    2
    Views:
    203
    Peter Sundstrom
    Nov 27, 2004
Loading...

Share This Page