in reply to Finding out non ASCII Characters in the text

Hi rsriram,

It seems like you're doing a lot of work for just looking for non-printable characters.  (Actually, they're ALL ascii characters, even the non-printable ones).  Also, I'm not sure why you're comparing with 121; the printable characters go all the way to 127 126 (= "~").  (Thanks ambrus, I knew that, but somehow my thinking was "off by one").

Instead of sorting, how about just applying the test to each character in the line?  Here's a subroutine which will return nonzero if the line contains non-printable characters, and zero otherwise:

sub line_contains_non_printable { my ($line) = @_; my @split = split //, $line; foreach (@split) { my $ord = ord($_); return 1 if ($ord < 32 || $ord > 126); } return 0; }

I'm sure there's at least several good modules for doing this as well (that I don't know of offhand), which other monks may be able to recommend.


s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Replies are listed 'Best First'.
Re^2: Finding out non ASCII Characters in the text
by ambrus (Abbot) on Jun 21, 2006 at 19:51 UTC
    ~ is character 126; character 127 is a control character.