Gossamer Forum
Home : General : Perl Programming :

Reg Exp help!!!!

Quote Reply
Reg Exp help!!!!
Hi there

I need to build a common header file, and as part of this, offer diffent page aspects depending upon the are of the site my visitors are in.

All pages are one level deep, eg

www.domain.com/area1/
or
www.domain.com/area1/pagename.shtml

but there are no subdomains. the only exception are one or two cgi- directories like:

www.domain.com/cgi-bin/area/

What perl expression can I use to pull in something like REQUEST_URI and chop it up just to give me a string with the current directory name?

ANY HELP would be absolutely great!!!!



Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Reg Exp help!!!! In reply to
Any ideas? Anyone?!




Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Reg Exp help!!!! In reply to
 
if ($ENV{'REQUEST_URI'} =~ m,/(.*?)/(.*?)\.(\w+),)
{
$dir = $1;
}
print "$dir";

Quote Reply
Re: Reg Exp help!!!! In reply to
Well done PerlKid!!

works a treat :D



Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Reg Exp help!!!! In reply to
Just to pick your brains a bit more.....

If I have the page at www.domain.com/blah/ it returns "" as the directory name. But if it has a page name in the URL it works fine.....

Any ideas?

Also, I need it to work with some cgi scripts, so the URL will be domain.com/cgi-bin/SOMETHING/

the 'if ($directory eq "cgi-bin")' bit I can do, but how can I read the SOMETHING appended if this is the case??

Thanks so much for your help!!!

Ben

Cheers!
Ben
------------
http://www.travel-experiences.com
Quote Reply
Re: Reg Exp help!!!! In reply to
umm.. i'm not sure what you are doing..

but here is just some stuff you can use..

($file) = $ENV{REQUEST_URI} =~ m#([^/])*$#;

$file is equal to the filename.. ie:

/blah/ returns ""
/blah/home.html return "home.html"

about the cgi-bin thing..

($dir) = $ENV{REQUEST_URI} =~ m#^/cgi-bin/(.*)$#;

/cgi-bin/SOMETHING/blah.cgi returns SOMETHING/blah.cgi

($dir) = $ENV{REQUEST_URI} =~ m#^/cgi-bin/([^/]*)#;

/cgi-bin/SOMETHING/blah.cgi returns SOMETHING

Jerry Su