Created
August 19, 2012 00:51
-
-
Save skaji/3390628 to your computer and use it in GitHub Desktop.
Changes the number of indent spaces.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Getopt::Long qw{:config auto_help}; | |
use Pod::Usage qw{pod2usage}; | |
GetOptions(\my %opt, qw{in=i out=i}) or pod2usage(1); | |
$opt{in} ||= 4; # the default number of input indent spaces | |
pod2usage(1) if !exists $opt{out}; | |
while (<>) { | |
if (/\A([ ]+)([^ ].*)\z/s) { | |
my $length = length $1; | |
my $level = int($length / $opt{in}); | |
my $reminder = $length % $opt{in}; | |
print ' ' x ($opt{out} * $level); | |
print ' ' x $reminder; | |
print $2; | |
} | |
else { | |
print; | |
} | |
} | |
__END__ | |
=head1 SYNOPSIS | |
$ indent.pl -i=8 -o=4 source.c | |
=cut |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment