rsriram has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Finding out non ASCII Characters in the text
by liverpole (Monsignor) on Jun 21, 2006 at 13:49 UTC | |
by ambrus (Abbot) on Jun 21, 2006 at 19:51 UTC | |
|
Re: Finding out non ASCII Characters in the text
by ptum (Priest) on Jun 21, 2006 at 13:53 UTC | |
|
Re: Finding out non ASCII Characters in the text
by prasadbabu (Prior) on Jun 21, 2006 at 13:43 UTC | |
|
Re: Finding out non ASCII Characters in the text
by Zaxo (Archbishop) on Jun 21, 2006 at 19:04 UTC |