Skip to content

Instantly share code, notes, and snippets.

@vifon
Last active May 24, 2018 12:27
Show Gist options
  • Save vifon/c8cdfc0e603bf9ec342612df94c4467f to your computer and use it in GitHub Desktop.
Save vifon/c8cdfc0e603bf9ec342612df94c4467f to your computer and use it in GitHub Desktop.
Make the heavily nested Perl docs more readable (though invalid POD)
#!/usr/bin/env perl
use warnings;
use strict;
use 5.010;
use constant INDENT_WIDTH => 2;
my $indent_level = 0;
sub indentation {
return " " x ($indent_level * INDENT_WIDTH);
}
sub reprint {
print indentation, shift // $_;
}
while (<>) {
if (/=over\b/) {
reprint;
reprint "{\n";
++$indent_level;
} elsif (/=back\b/) {
--$indent_level;
reprint "}\n";
reprint;
} else {
if (/\S/) {
reprint;
} else {
print;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment