http://www.perlmonks.org?node_id=358647

#!/usr/bin/perl -w use strict; use CGI qw(:standard); my $query = new CGI; use CGI::Carp qw(fatalsToBrowser); ##################################################################### # DESCRIPTION ##################################################################### # The purpose of this script is to provide a simple way to switch # between the French and English versions of a website. In order to # function properly, the script requires that a standard naming # convention be used on both the French and English versions of the # website. ##################################################################### # CONFIGURATION ##################################################################### my %OPTIONS = ( en_extension => '_e', fr_extension => '_f', en_directory => 'en', fr_directory => 'fr', ); ##################################################################### # PLEASE DO NOT MODIFY ANYTHING BELOW THIS LINE ##################################################################### # Switch to English or French? my $lang = $query->param('lang'); # The http address of the page calling this script my $referrer = $query->referer; # Initialize the $final_url variable my $final_url = "$referrer"; # Change the $final_url variable as per instructions stored in the # $lang variable if ($lang eq "en") { $final_url =~ s/$OPTIONS{'fr_directory'}/$OPTIONS{'en_directory'}/ +i; $final_url =~ s/$OPTIONS{'fr_extension'}\.html/$OPTIONS{'en_extens +ion'}\.html/i; } elsif ($lang eq "fr") { $final_url =~ s/$OPTIONS{'en_directory'}/$OPTIONS{'fr_directory'}/ +i; $final_url =~ s/$OPTIONS{en_extension}\.html/$OPTIONS{fr_extension +}\.html/i; } # Go to the page requested print $query->redirect("$final_url");