Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

problems with Perl RegEx match
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 = $';
}

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.

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.

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.
Thanks for all your help in this matter.

Regards,

Mitch


Report this thread to moderator Post Follow-up to this message
Old Post
mitch
12-28-04 01:56 AM


Re: problems with Perl RegEx match
mitch wrote:
> 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 = $';
> }

That code works fine for me.

> 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.

So, what's at (and right before and after) line 64 in your script?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Report this thread to moderator Post Follow-up to this message
Old Post
Gunnar Hjalmarsson
12-28-04 08:56 AM


Re: problems with Perl RegEx match
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")}'

Report this thread to moderator Post Follow-up to this message
Old Post
Abigail
12-28-04 08:56 AM


Re: problems with Perl RegEx match
In our last episode,
<1104192460.971234.138440@f14g2000cwb.googlegroups.com>, the
lovely and talented mitch broadcast on comp.lang.perl.misc:

> 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 = $';
> }

I'm not following all of this but, why make things hard on
yourself.  Use any other quote character besides /, and you
won't have to escape them.  Also as you would see, if you even
took a glance at perlretoot, / is NOT special in [].

m#http://([^/]+)#

isn't that about 100 times easier to read and work with?

(However, even as it stands, your snippet works fine for
me.)

> 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.

Useless without all of the code.  Pretty likely the problem is
above the snippet.

You know there is a module to parse URLs.  So, howcome reinvent
the wheel?

> 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$

Yeah, that really doesn't work, even without garbage above it,
but nothing will work because you did not include in the
original snip the part with the real problem.

> 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.

> 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.
> Thanks for all your help in this matter.

> Regards,

> Mitch

--
Lars Eighner              eighner@io.com           [url]http://www.io.com/~eighner/[/ur
l]
Behaviorism is the art of pulling habits out of rats.  -- O'Neill

Report this thread to moderator Post Follow-up to this message
Old Post
Lars Eighner
12-28-04 08:56 AM


Re: problems with Perl RegEx match
Hi everyone,

Thanks first of all for all the great comments and suggestions. So
Abigail, you were right, I foolishly forgot to close a silly brace.
That should teach me to write code after only sleeping for two hours
(boy do I feel sheepish).

In terms of indenting, my code is beautifully indented, however while
posting it, the tabs and spaces had been removed.  Next time I'll add
some HTML code to the posting, just so that it gets formatted properly.


In any event, I appreciate all the comments and thanks again for the
prompt response. It took me literaly 10 seconds to find the missing
brace. I guess sometimes you have been staring too long at the code to
see the problem. I was convinced that the problem was in the RegEx.
Well, live and learn.... thanks again folks.

Regards,

Mitch


Report this thread to moderator Post Follow-up to this message
Old Post
mitch
12-28-04 08:57 PM


Re: problems with Perl RegEx match
mitch (mitch_christow@biogen.com) wrote on MMMMCXXXVII September MCMXCIII
in <URL:news:1104248521.746602.313050@f14g2000cwb.googlegroups.com>:
%%
%%  In terms of indenting, my code is beautifully indented, however while
%%  posting it, the tabs and spaces had been removed.  Next time I'll add
%%  some HTML code to the posting, just so that it gets formatted properly.

Adding HTML code is a sure way of getting killfiled by those who are
most likely to answer your queries.

If whitespace gets removed, get a better newsagent.


Abigail
--
perl -Mstrict='}); print "Just another Perl Hacker"; ({' -le1

Report this thread to moderator Post Follow-up to this message
Old Post
Abigail
12-29-04 01:57 AM


Re: problems with Perl RegEx match
"mitch" <mitch_christow@biogen.com> wrote in message
news:1104248521.746602.313050@f14g2000cwb.googlegroups.com...
: Hi everyone,
:
: Thanks first of all for all the great comments and suggestions. So
: Abigail, you were right, I foolishly forgot to close a silly brace.
: That should teach me to write code after only sleeping for two hours
: (boy do I feel sheepish).
:
: In terms of indenting, my code is beautifully indented, however while
: posting it, the tabs and spaces had been removed.  Next time I'll add
: some HTML code to the posting, just so that it gets formatted properly.

Don't do that.  Just replace the tabs with an appropriate number of spaces
(3 or 4 should be fine)

--
Wyzelli



Report this thread to moderator Post Follow-up to this message
Old Post
Peter Wyzl
12-29-04 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:23 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.