Breaking a domain

Hi!

I am starting a redirection service on some of my domain names.  It uses Wild Cards domains and when someone types anything.mydomain.com the script is run.  It gets the $ENV{'HTTP_HOST'} and stores it into $url.  

How can I 'break' it so the $url value is broken into 2 parts and stored.  So the value in $url would be

therename.mydomain.com

The 'therename' part is stored in $username and the 'mydomain.com' is stored in $address.

Any ideas?  Thanks in advance!  Happy Christmas to everyone!

Graeme Sandwell
graemesandwellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

frugalCommented:
I quickly hacked up something here. Bear in mind that I'm not that great with regular expressions so if you're a whiz with them you might be able to get it a bit simpler but this works. Read the comments for more info on how it works. I hope this is clear!

#!/usr/local/bin/perl

# get the domain, this would be coming
# from somewhere else in your script.
$domain = "my.domain.com";

# the split function uses the regular
# expression specified (in this case .
# which I had to escape because it's a
# reserved character in reg exps) as a
# seperator and spits out the rest as an
# array of values. In this case the first
# value goes to the $host variable. The
# rest goes to an array, @domain.
($host,@domain) = split(/\./,$domain);
# join does the reverse of split, it
# joins an array into one string using
# the specified character as a seperator # (in this case . again).
$domain = join(".",@domain);
# print the output, in your case I assume
# this would actually be a redirect.
print "Host is $host\n Domain is $domain\n";
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
#assuming $host is the part before the first .
($host,$domain) = split(/\./,$domain,2);
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.