Created
February 9, 2011 15:43
-
-
Save artemave/818678 to your computer and use it in GitHub Desktop.
find files with non-ascii content
This file contains 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/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