in reply to Rogue Null (ordinate 0) characters in text files
Unless you really want to print every time you find a rougue char you can just use tr:
$str = join '', map{chr}0..255; $str =~ tr/\11\12\40-\176//cd; # ascify aka remove all crap char +s print $str, $/;
The /c is complement the list of desired characters, the /d deletes those that don't match. The good printable ASCII characters are specified in octol but you can use hex. To do what you are doing with a regex (here the chars are expressed as hex just to shown TIMTOWTDI):
while (<DATA>) { while ( m/([^\x09\x0A\x20-\x7E])/g ) { printf "Found chr %d on line %d at pos %d\n", ord($1), $., pos +($_); } }
|
|---|