Gossamer Forum
Home : General : Perl Programming :

print $1 if $ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/;

Quote Reply
print $1 if $ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/;
I would like to use the following code into a script, but i get a 500 error every time
Code:
if $ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/ {
$host=$1;
}
orginal code THAT WORKS!:

Code:
print $1 if $ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/;

Quote Reply
Re: print $1 if $ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/; In reply to
With if (condition) { .. } you need round brackets around the condition. So:

if ($ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/) {
$host=$1;
}

should work. As well as:

my ($host) = $ENV{'REMOTE_HOST'} =~ /.*\.([^.]*\.[^.]*)/;

as a one liner.

Cheers,

Alex