Created
September 12, 2016 18:57
-
-
Save mcsnolte/825d55e5ef92a799cedee2081829900f to your computer and use it in GitHub Desktop.
Finds characters you probably don't need
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
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| use open qw(:std :utf8); | |
| my %badchars; | |
| while (my $line = <>) { | |
| my @bad = ( $line =~ m/([^[:print:][:space:]])/g); # find all bad characters | |
| if (@bad) { | |
| for my $badch (@bad) { | |
| $badchars{$badch}++; | |
| } | |
| my $badlist = join ' ', map { sprintf( "%02x", ord $_ ) } @bad; | |
| warn "line $. contains bad char(s) ($badlist): $line"; | |
| } | |
| } | |
| for my $badch ( sort keys %badchars ) { | |
| printf "%6d %02x %s\n", $badchars{$badch}, ord($badch), $badch; | |
| } | |
| unless ( keys %badchars ) { | |
| print "ok\n"; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment