-
Notifications
You must be signed in to change notification settings - Fork 0
/
WhiteSpace.pl
45 lines (41 loc) · 881 Bytes
/
WhiteSpace.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
#!perl
# WhiteSpace.pl
# This script will recursivley remove trailing spaces from all lines in all specified files.
# You can specifiy extensions in Subtoutine remove_ws.
#
use File::Path;
use File::Find;
use Tie::File;
my $dir = shift;
if ($dir ne '')
{
&main();
exit;
}
else
{
print "WhiteSpace.pl should be called like\"WhiteSpace.pl C:/Path/To/Directory\"";
exit;
}
sub main
{
&File::Find::finddepth(\&remove_ws,"$dir");
exit;
}
sub remove_ws
{
print "Checking $File::Find::name\n";
return if (-d $File::Find::name);
# Check Extension Here.
if ($File::Find::name =~ /^.*\.(php|js)$/)
{
print "$File::Find::name is a PHP or JS file. Removing WS.\n";
tie @lines, 'Tie::File', $File::Find::name or die;
for(@lines)
{
s/^(.*?)\s+$/$1/g;
}
untie @lines;
}
return;
}