-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword_refactor.pl
executable file
·34 lines (31 loc) · 997 Bytes
/
word_refactor.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
#!/usr/bin/env perl
use Getopt::Long;
my @maps;
# negated character class that consists of the set of characters forming an "identifier" like a variable name
my $negative_word_regex="[^0-9A-Za-z_]";
GetOptions (
#examples
"maps=s@" => \@maps,
"negative_word_regex=s" => \$negative_word_regex,
)
or die("Error in command line arguments\n");
foreach (@maps) {
#print $_;
@map = split(/=/,$_);
$substitutions{ $map[0] }=$map[1];
}
while (<>) {
#print s/\Q$word_regex\E/f/g;
for my $key (keys %substitutions)
{
my $subst = "s/(?<=${negative_word_regex})${key}(?=${negative_word_regex})/${substitutions{$key}}/g" ;
eval($subst);
$subst = "s/\^${key}(?=${negative_word_regex})/${substitutions{$key}}/g" ;
eval($subst);
$subst = "s/(?<=${negative_word_regex})${key}\$/${substitutions{$key}}/g" ;
eval($subst);
$subst = "s/\^${key}\$/${substitutions{$key}}/g" ;
eval($subst);
}
print $_;
}