Skip to content

Instantly share code, notes, and snippets.

@skaji
Created August 19, 2012 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skaji/3390628 to your computer and use it in GitHub Desktop.
Save skaji/3390628 to your computer and use it in GitHub Desktop.
Changes the number of indent spaces.
#!/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