-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspacer
More file actions
executable file
·42 lines (35 loc) · 842 Bytes
/
spacer
File metadata and controls
executable file
·42 lines (35 loc) · 842 Bytes
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
#!/usr/bin/env perl
# martin, 2018-09-02, 2018-12-19, 2019-10-21
# ./spacer hello => "h e l l o"
# ./spacer -meme hello => "hello"
# ./spacer -sponge i'm the bad guy... duh! => "i'm thE baD gUY... DUh!"
use strict;
use warnings;
use utf8;
binmode(STDIN, ':utf8');
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
sub spaced {
s/([^\s])/$1 /gr . " "
}
sub fullwidth {
my $delta = ord('!') - ord('!');
return
join '',
map { chr(ord($_) + $delta) }
split //, $_[0];
}
sub spongecase {
return
join '',
map { rand >= 0.5 ? uc $_ : lc $_ }
split //, $_[0];
}
if ($ARGV[0] =~ /--?meme/) {
print fullwidth($_), " " for @ARGV[1..$#ARGV];
} elsif ($ARGV[0] =~ /--?sponge/) {
print spongecase($_), " " for @ARGV[1..$#ARGV];
} else {
print spaced($_) for @ARGV;
}
print "\n";