perl question [OT]

A

Anonymous

Guest
sorry a question about perl ..

this line

my ($newhost) = $ENV{'HTTP_HOST'};

returns

http://www.mydomain.com

but on my $newhost i need only mydomain.com without "www."


What can I do , my perl experience is very low , anyone can help me ?

Thanks !!!
 
anyone , or at least where can I find a perl forum ?

thanks
 
leon said:
sorry a question about perl ..

this line

my ($newhost) = $ENV{'HTTP_HOST'};

returns

http://www.mydomain.com

but on my $newhost i need only mydomain.com without "www."


What can I do , my perl experience is very low , anyone can help me ?

Thanks !!!

You can replace your code with the following code. It is untested but it should work.

Code:
my ($newhost) = $ENV{'HTTP_HOST'};

if ($ENV{'HTTP_HOST'}=~/^www./) {
   $newhost =~ s/www.//g;
}

Hope that this helps. What it is actually doing is checking to see if there is a "www." at the begining and if there is it removes it.

Sorry, the first method will remove the last "www." in the $new host field. Usually this will work however if you run into http://www.mywww.com it will return http://www.mycom. So use the method below, it checks if it exists and if it does it removes the first 4 characters from the begining.

Code:
if ($ENV{'HTTP_HOST'}=~/^www./) {
   $hostlength = length ($ENV{'HTTP_HOST'});
   $newhost = substr($ENV{'HTTP_HOST'}, 3, $hostlength);
}

The code above will also create the $newhost variable and replace your line of code:

Code:
my ($newhost) = $ENV{'HTTP_HOST'};

Hope that this helps
 
Back
Top