Skip to content

Instantly share code, notes, and snippets.

@artemave
Created February 9, 2011 15:43
Show Gist options
  • Save artemave/818678 to your computer and use it in GitHub Desktop.
Save artemave/818678 to your computer and use it in GitHub Desktop.
find files with non-ascii content
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
File::Find::find(
sub {
return unless -f;
#refine further with a return unless /\.php$/ if desired
return unless /\.(html|js|css|rb)$/;
open my $fh, "<", $_
or die "could not open $_";
while (<$fh>) {
my $offset = 0;
for my $char (split //) {
if (ord $char > 127) {
printf "non-ascii char (%04x) in file %s on line %d position %d:\n%s\n",
ord($char), $File::Find::name, $., $offset, $_;
}
$offset++;
}
}
},
@ARGV
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment