Re: problems with Perl RegEx match

From: Abigail (abigail_at_abigail.nl)
Date: 12/28/04


Date: 28 Dec 2004 00:42:17 GMT

mitch (mitch_christow@biogen.com) wrote on MMMMCXXXVII September MCMXCIII
in <URL:news:1104192460.971234.138440@f14g2000cwb.googlegroups.com>:
!! Hi folks,
!!
!! I am working on a what I thought would be fairly simple regular
!! expression search. I am simply trying to take a full URL (something
!! like http://www.someurl.com/someDir/file.html) and parse it out into
!! its components domain and path (domain = www.someurl.com & path =
!! /someDir/file.html). So I wrote this little script to do just that.
!! However, I am getting an error when I run my script and I think it has
!! something to do with my regex function that I am using. So here is the
!! code snippet of the offending line:
!!
!! if ($externalLink =~ m/http:\/\/([^\/]+)/) {
!! $domain = $1;
!! $path = $';
!! }

It really, really helps to make your code fragments more readable.
If your regex itself has slashes, use different delimiters, so your
regex isn't sprinkled with slashes. And INDENT:

    if ($externalLink =~ m!http://([^/]+)!) {
        $domain = $1;
        $path = $';
    }

!! The error that I am getting is this:
!! Missing right bracket at ./LogPreProcessor_Inetprod.pl line 64, at end
!! of line
!! syntax error at ./LogPreProcessor_Inetprod.pl line 64, at EOF
!! Execution of ./LogPreProcessor_Inetprod.pl aborted due to compilation
!! errors.

That error doesn't sound it has anything at all to do with the regexp
given. The error strongly suggests you have left of a right (closing)
bracket somewhere in your code, and upon reaching the end of the file,
Perl didn't encounter it.

Count your opening and closing brackets.

!! I also tried to modify the script by removing the \ from within the
!! square brackets:
!!
!! if ($externalLink =~ m/http:\/\/([^/]+)/) {
!! $domain = $1;
!! $path = $';
!! }
!!
!! But that too gives me an error:
!! bash-2.03$ LogPreProcessor_Inetprod.pl inet.log
!! /http://([^/: unmatched [] in regexp at ./LogPreProcessor_Inetprod.pl
!! line 26.
!! bash-2.03$
!!
!! So I tried a bunch of other variations, wich also did not work. After
!! consulting several books and googling for some solution, I thought that
!! I had exhausted all my research possibilities and I thought that the
!! smart folks in this group could show me the error of my ways.

Error messages can also be found in the 'perldiag' manual page.

!! On a side note, when I used the following search term in google to look
!! for a solution:
!!
!! Perl "[^/]"
!!
!! Google seemed to ignore all those special characters, and simply
!! returned any page that contained the term 'Perl'. So that was useless.

Yes. But why on earth would you look for 'Perl "[^/]"'? You get an error
message. Why didn't you a search for that error message? I googled for

    "Missing right bracket" Perl

and the fourth hit told me exactly what happened. Which isn't too bad,
considering it's an error message from an older Perl - in newer Perls,
the error message is rephrased.

-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


Relevant Pages

  • Re: About the error message in Perl : "Missing right curly braces"
    ... Subject: About the error message in Perl: "Missing right curly ... SKY and the SKY marks are trade marks of ... track which line contains that curly brace which is causing that problem, ...
    (perl.beginners)
  • Re: "Did not find leading dereferencer" - new findings to an old puzzle
    ... to do with the "Dereferencer" error, because on the first example I ... I got that error message in the context of Perl standard ... this would not explain why the error message ... source code. ...
    (comp.lang.perl.misc)
  • Re: perl and CGI
    ... This error message is _not_ a Perl error message. ... I was just trying to figure out how perl and the web server works.. ... I have already developed a perl file to manage a web form (send the ... pointers to more information. ...
    (comp.lang.perl.misc)
  • RE: lc
    ... > and I got an error message that said I couldn't use lc ... Then I checked my copy of Learning Perl and the index ... that Perl didn't have a lowercase function. ... Mail SpamGuard - Read only the mail you want. ...
    (perl.beginners)
  • Re: monthly & quarterly Summery
    ... One bracket too many ... But your formula returns error message for my Question 2. ... mesage that "the formula you have entered has an error" ... put the month number in a acell and use ...
    (microsoft.public.excel.misc)