Skip to content

Instantly share code, notes, and snippets.

@bentglasstube
Created January 30, 2015 20:25
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 bentglasstube/c876a32ab8331585f4a3 to your computer and use it in GitHub Desktop.
Save bentglasstube/c876a32ab8331585f4a3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
# Lines that start with any of these words will be left-aligned
# Also lines that are labels or comments or empty
# Anything else will be indented by exactly one tab
my @leftwords = qw(
segment
global
);
my $leftwords = join '|', @leftwords;
my $leftcheck = qr/^($|;|\w+:|$leftwords)/;
while (my $line = <>) {
$line =~ s/^\s+//;
$line =~ s/\s+$//;
my $indent = ($line =~ $leftcheck) ? 0 : 1;
print +("\t" x $indent), $line, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment