K
Ken Sington
Here's a function I wrote.
The function is incomplete at the moment because I'm still writing it.
But from what I have now, what do you think?
If you just look at the code and the comments; if I suddently became rich and
quit my job and you just took over this contract (we never meet), and you see code like the function
below, will you have any trouble?
#---------------------------------.---------------------------------#
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ . ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PASSING PARAMETERS ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ . ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#===============================--.--===============================#
# to use:
# ¶mPass('option','name=value',$ENV{'QUERY_STRING'});
# arg 1: options
# add <-- add new name=value pairs
# change <-- changes values for each name given
# explicit <-- return only these name=value pairs
# delete <-- delete name=value pairs
# arg 2: items
# if option=add <-- provide new name=value&name2=value2 pairs to be added
# if option=change <-- provide name=newValue&name2=NewValue2& etc...
# if option=explicit <-- provide varName&varName2 of pairs to be passed
# if option=delete <-- provide varName&varName2 of pairs to be deleted
# arg 3: $ENV{QUERY_STRING}
sub paramPass {
my ($option,$nameValue,$env)=@_;
my $returnIt;
my $work = $env;
if ($option eq "add"){
$returnIt = $env . "&" . $nameValue;
} else {
my @env = split /&/, $env;
my @nameValue = split /&/, $nameValue;
for my $line (@env){
my ($name, $value) = split /=/,$line,2; # solves problem: name=value=3445, where
value \
has "=" in it
my $blnMatched="false";
my ($nHold,$vHold);
for my $nv (@nameValue){
my ($n,$v) = split /=/,$nv, 2;
($nHold, $vHold, $blnMatched) = ($n, $v, "true") if ($name eq $n);
}
$work =~ s/$name/$nHold=$vHold/ if ($blnMatched eq "true" && $option eq "change");
# placeholder...up to here
}
$returnIt = $work;
}
return $returnIt;
}
The function is incomplete at the moment because I'm still writing it.
But from what I have now, what do you think?
If you just look at the code and the comments; if I suddently became rich and
quit my job and you just took over this contract (we never meet), and you see code like the function
below, will you have any trouble?
#---------------------------------.---------------------------------#
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ . ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ PASSING PARAMETERS ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ . ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ #
#===============================--.--===============================#
# to use:
# ¶mPass('option','name=value',$ENV{'QUERY_STRING'});
# arg 1: options
# add <-- add new name=value pairs
# change <-- changes values for each name given
# explicit <-- return only these name=value pairs
# delete <-- delete name=value pairs
# arg 2: items
# if option=add <-- provide new name=value&name2=value2 pairs to be added
# if option=change <-- provide name=newValue&name2=NewValue2& etc...
# if option=explicit <-- provide varName&varName2 of pairs to be passed
# if option=delete <-- provide varName&varName2 of pairs to be deleted
# arg 3: $ENV{QUERY_STRING}
sub paramPass {
my ($option,$nameValue,$env)=@_;
my $returnIt;
my $work = $env;
if ($option eq "add"){
$returnIt = $env . "&" . $nameValue;
} else {
my @env = split /&/, $env;
my @nameValue = split /&/, $nameValue;
for my $line (@env){
my ($name, $value) = split /=/,$line,2; # solves problem: name=value=3445, where
value \
has "=" in it
my $blnMatched="false";
my ($nHold,$vHold);
for my $nv (@nameValue){
my ($n,$v) = split /=/,$nv, 2;
($nHold, $vHold, $blnMatched) = ($n, $v, "true") if ($name eq $n);
}
$work =~ s/$name/$nHold=$vHold/ if ($blnMatched eq "true" && $option eq "change");
# placeholder...up to here
}
$returnIt = $work;
}
return $returnIt;
}