-
Notifications
You must be signed in to change notification settings - Fork 1
/
url-encode.pl
executable file
·102 lines (71 loc) · 1.76 KB
/
url-encode.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/env perl
# url-encode.pl
########################################################################
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use Pod::Usage;
########################################################################
# GET OPTIONS
#
my ( $input, $help, $wants_docs );
GetOptions (
"input=s" => \$input,
"help" => \$help,
"documentation" => \$wants_docs,
) or die pod2usage ( -msg => "Invalid parameter" -exitval => 2 );
if ( $help ) {
pod2usage ( -exitval => 0, -verbose => 0 );
}
if ( $wants_docs ) {
pod2usage ( -verbose => 2 );
}
#
########################################################################
########################################################################
# MAIN PROGRAM
#
if ( not $input ) { #Getting from STDIN
my @input = <STDIN>;
chomp @input;
$input = join "\r\n", @input;
chomp $input;
}
for my $char ( split //, $input ) {
if ( ord $char < ord "0" ) {
printf "%%%02x", ord $char;
}
else {
print "$char";
}
}
print "\n";
#
# DONE
########################################################################
=pod
=head1 NAME
urlencode.pl
=head1 SYNOPSIS
url-encode -input "my string to URL encode"
my%20string%20to%20URL%20encode
url-encode <<<"my string to URL encode"
my%20string%20to%20URL%20encode
url-encode "my string to URL encode" | url-encode.pl
my%20string%20to%20URL%20encode
=head1 DESCRIPTION
This program takes a string and URL encodes it
It returns the string onto STDOUT
=head1 OPTIONS
=over 5
=item -input
The string you want to url-encode
=item -help
Prints help text
=item -documentaion
Prints out this whole friggin' document
=back
=head1 AUTHOR
David Weintraub L<mailto:dweintraub@travelclick.com>
=cut