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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Nov 7, 2000, 4:34 AM

Post #1 of 3 (3104 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

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

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


Enthusiast / Moderator

Nov 7, 2000, 4:47 AM

Post #2 of 3 (3104 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);

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!(/(?:[^/]*/)*)!;

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


Nov 7, 2000, 7:37 AM

Post #3 of 3 (3104 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