my %map = (
';' => "%3B",
',' => "%2C",
'=' => "%3D",
);
my $converter = generate_converter(\%map);
my $a = ';,= ';
warn $converter->($a);
sub generate_converter {
my ($ref_map) = @_;
my $converter = sub
{
my ($str) = @_;
$str =~ s/([;,=])/$ref_map->{$1}/g;
return $str;
};
return $converter;
}
这样写比较好理解
my %map =
(
';' => "%3B",
',' => "%2C",
'=' => "%3D",
);
my $a = ';,= ';
$a =~ s/([;,=])/$map{$1}/g;
warn $a;
';' => "%3B",
',' => "%2C",
'=' => "%3D",
);
my $converter = generate_converter(\%map);
my $a = ';,= ';
warn $converter->($a);
sub generate_converter {
my ($ref_map) = @_;
my $converter = sub
{
my ($str) = @_;
$str =~ s/([;,=])/$ref_map->{$1}/g;
return $str;
};
return $converter;
}
这样写比较好理解
my %map =
(
';' => "%3B",
',' => "%2C",
'=' => "%3D",
);
my $a = ';,= ';
$a =~ s/([;,=])/$map{$1}/g;
warn $a;