output asked headers in the order they were asked; avoid header name spoofing by...
[hband-tools.git] / user-tools / url_encode
blob5531becb6257a7348dbb6c3dfb1c37bc8e17a41b
1 #!/usr/bin/env perl
3 sub decode {
4 $_[0] =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
5 return $_[0];
7 sub encode {
8 $_[0] =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
9 return $_[0];
13 if($0 =~ /decode/) {
14 $fgv = \&decode;
16 else {
17 $fgv = \&encode;
21 if(scalar @ARGV > 0) {
22 # parameters given
23 print $fgv->(join " ", @ARGV);
25 else {
26 # process stdin
27 print $fgv->($_) while(<STDIN>);
31 __END__
33 =pod
35 =head1 NAME
37 url_encode - Escape URL-unsafe chars in text given either in parameters or in stdin by percent-encoding
39 url_decode - Unescape percent-encoded sequences given either in parameters or in stdin
41 =cut