PerlFlunkie wrote:
One thing you can do to simplify your mod is to make common code snippets into a subroutine.I did so.
Code for the subroutine in db_utils.pl:
Code:
sub cleanup {
#-----------------------------------------
# get rid of extra characters
my($input) = shift;
$input =~ s/ä/ae/g;
$input =~ s/Ä/Ae/g;
$input =~ s/ö/oe/g;
$input =~ s/Ö/Oe/g;
$input =~ s/ü/ue/g;
$input =~ s/Ü/Ue/g;
$input =~ s/ß/ss/g;
$input =~ s/\@/-at-/g; # @
$input =~ s/\//-/g; # /
$input =~ s/\&/\-und-/g; # &
$input =~ s/\%/\-Prozent-/g; # %
$input =~ s/ /\-/g; # Leerzeichen - empty space
$input =~ s/\(/\-/g; # (
$input =~ s/\)/\-/g; # )
$input =~ s/!/\-/g; # !
$input =~ s/_/-/g;
$input =~ s/\+/\-und-/g; # +
$input =~ s/,/\-/g; # ,
$input =~ s/\>/\-/g; # >
$input =~ s/\:/\-/g; # :
$input =~ s/®/\-/g; # ®
$input =~ s/©/\-/g; # ©
$input =~ s/º/\-/g; # Nº
$input =~ s/\«/\-/g; # «
$input =~ s/\»/\-/g; # »
$input =~ s/\*/\-/g; # *
$input =~ s/²/\-/g; # ²
$input =~ s/\?/\-/g; # ?
$input =~ s/\./\-/g; # .
$input =~ s/`/\-/g; # `
$input =~ s/´/\-/g; # ´
$input =~ s/\'/\-/g; # '
$input =~ s/’n/\-/g; # ’
$input =~ s/\{/\-/g; # {
$input =~ s/\}/\-/g; # }
$input =~ s/\[/\-/g; # [
$input =~ s/\]/\-/g; # ]
$esc =~ s/^\s-|\s-$//gs;
$esc =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg;
$esc =~ s/([^a-zA-Z0-9_\-.()[]%ae!+,>%O9)/uc sprintf("%%%02x",ord($1))/eg;
$esc =~ s/\%20/\-/g; #
$esc =~ s/\%23/\-/g; #
$esc =~ s/\%09/\-/g; #
$esc =~ tr/--/-/s; # get rid of multiple - charakters
return $input;
}
Code for Einschub $ Echte URL in nph-build.cgi ( sub build_update_newpop ) :
Code:
####################### Einschub $ Echte URL ###################################
##### Variante 1 : Detailed Folder ####
my($esc) = $values[$db_title];
$esc = &cleanup($esc);
## Kategorie hinzufügen - Now let`s add the category:
my($esd) = $values[$db_category] ."-";
$esd =~ s/\//-/g;
$esd =~ s/_/-/g;
## <%ID%> hinzufügen - Now let`s add the $db_key
$esd = $values[$db_key] ."-" .$esd;
$esd = $esd .$esc;
$esd =~ tr/-/-/s; # replace character for subtraction
$esd =~ tr/--/-/s; # get rid of multiple - charakters
$esd =~ tr/[A-Z]/[a-z]/; # change all letters to lowercase
$values[$db_echteURL] = $esd;
$echteURL = $esd;
## <%echteURL%> = 3043-grafik-bildbearbeitung-speziell-fuer-soko
####################### Einschub $ Echte URL ###################################
It works fine -
.
Andreas
Dr.Windows