Skip to content

Instantly share code, notes, and snippets.

@mcsnolte
Created September 12, 2016 18:57
Show Gist options
  • Select an option

  • Save mcsnolte/825d55e5ef92a799cedee2081829900f to your computer and use it in GitHub Desktop.

Select an option

Save mcsnolte/825d55e5ef92a799cedee2081829900f to your computer and use it in GitHub Desktop.
Finds characters you probably don't need
#!/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