CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
Chopping up $env{REQUEST_URL}

 



BenSeb
Deleted

Nov 7, 2000, 4:34 AM

Post #1 of 3 (2066 views)
Chopping up $env{REQUEST_URL} Can't Post

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


japhy
Enthusiast / Moderator

Nov 7, 2000, 4:47 AM

Post #2 of 3 (2066 views)
Re: Chopping up $env{REQUEST_URL} [In reply to] Can't Post

The directory name starts at the first / and goes to the last /, correct? No regex needed here at all.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


my $bpos = index $ENV{REQUEST_URL}, '/';
my $epos = rindex $ENV{REQUEST_URL}, '/';
my $dir = substr($ENV{REQUEST_URL}, $bpos, 1 + $epos - $bpos);
</pre><HR></BLOCKQUOTE>

If you really want to use a regex, then I'd suggest:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


my ($dir) = $ENV{REQUEST_URL} =~ m!(/(?:[^/]*/)*)!;
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



BenSeb
Deleted

Nov 7, 2000, 7:37 AM

Post #3 of 3 (2066 views)
Re: Chopping up $env{REQUEST_URL} [In reply to] Can't Post

Cheers! I'll give it a go :)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives