I am writing a script to find out whether all the characters in a file are keyboard characters. For that, I am adding every line to a array, sort them and check the ASCII value of the first, second(I check this because the first will be a carriage return) and the last character. If the character is less than ASCII number 31 or greater than 121 and not equal to 10 (which is the carriage return), the program should report a error. Something fuzzy happens in the script and I get the error message even where the character is within the range. Can you please help me out?
@splitted = split("",$_);
@sorted = sort(@splitted);
if ((ord(@sorted[0]) < 31 && ord(@sorted[0]) != 10)||ord(@sorted[0]) > 121)
{
print "Non-ASCII character found in the content";
}
if ((ord(@sorted[1]) < 31 && ord(@sorted[1]) != 10)||ord(@sorted[1]) > 121)
{
print "Non-ASCII character found in the content";
}
if ((ord(@sorted[-1]) < 31 && ord(@sorted[-1]) != 10)||ord(@sorted[-1]) > 121)
{
print "Non-ASCII character found in the content";
}
Or is there any other way to find out whether the character is out of this range?
Sriram
In reply to Finding out non ASCII Characters in the text by rsriram
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |