Gossamer Forum
Home : General : Perl Programming :

if, elsif, else and matching

Quote Reply
if, elsif, else and matching
Argh :-(

Why does this always end up going through the loop and settling for the 'else' statement every time - even though all the others are true?

Code:
sub translate {

my $referrer = $ENV{HTTP_REFERER};
my $goto = $referrer;

if ($referrer =~ m|/en/|g) {
$goto =~ s|/en/|/ws/|g;
}
elsif ($referrer =~ m|/ws/|g) {
$goto =~ s|/ws/|/en/|g;
}
elsif ($referrer =~ m|lang=en|g) {
$goto =~ s|lang=en|lang=ws|g;
}
elsif ($referrer =~ m|lang=ws|g) {
$goto =~ s|lang=ws|lang=en|g;
}
else {
die("Can't understand what to translate to.");
}

print $query->redirect($goto);

}

I'm using this on URLs such as the following two, but it never matches for some bizarre reason. Can someone spot where I'm, going wrong?

Code:
http://www.geo-drws.co.uk/html/en/places.html
http://www.geo-drws.co.uk/cgi-bin/odb.cgi?browse=places;res_places=1;res_places_sl=1;lang=en;

- wil

Last edited by:

Wil: May 9, 2002, 2:04 AM
Quote Reply
Re: [Wil] if, elsif, else and matching In reply to
Never mind. Problem solved.

If anyone's curious is to do with my links being constructed by JavaScript, i.e.:

Code:
onClick="javascript:location.href='/html/en/links.html';"

Which doesn't pass any REFERRER onto the server. Marvellous! <g>.

- wil
Quote Reply
Re: [Wil] if, elsif, else and matching In reply to
You also don't need g's in your regex.

Trying printing the referer to see what it prints.

Last edited by:

Paul: May 9, 2002, 2:11 AM
Quote Reply
Re: [Paul] if, elsif, else and matching In reply to
I'm gutted that the javascript technique mentioned doesn't send any env. variables to the server. I'm going to turn off javascript in my browser out of protest ;-)

- wil