Created
December 18, 2013 11:59
-
-
Save nordicdyno/8021152 to your computer and use it in GitHub Desktop.
find only ASCII Pod
Example: find . -type f -exec perl check_pod.pl {} \;
This file contains hidden or 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
| use strict; | |
| use warnings; | |
| use feature 'say'; | |
| use autodie qw(open close); | |
| use open IO => ":encoding(UTF-8)", ":std" => ":utf8"; | |
| my $file = $ARGV[0]; | |
| my @pods; | |
| my ($line, $line_start, $is_pod, $pod_body) = (0, 0, 0, ""); | |
| open (my $fh, '<', $file); | |
| while (<$fh>) { | |
| $line++; | |
| if (/^=(\w+)/) { | |
| if ($1 eq 'cut') { | |
| $pod_body .= $_; | |
| push @pods, [$line_start, $line, $pod_body]; | |
| $pod_body = ""; | |
| $is_pod = 0; | |
| } | |
| else { | |
| $line_start = $line unless $is_pod; | |
| $is_pod = 1; | |
| } | |
| } | |
| next unless $is_pod; | |
| $pod_body .= $_; | |
| } | |
| my $message = "$file:\n"; | |
| my @ascii_only; | |
| for (@pods) { | |
| my ($start, $end, $body) = @$_; | |
| if ($body !~ /[^[:ascii:]]+/m) { | |
| push @ascii_only, "[$start:$end]\n$body"; | |
| } | |
| } | |
| say $message . join("\n", @ascii_only) if @ascii_only; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment