paulnovl has asked for the wisdom of the Perl Monks concerning the following question:
That gives the expected results for most of my text files, e.g. a text file that contains ^Z on line 15 will yield:BEGIN{ @ARGV == 1 or warn "\n\tUsage: $0 FILE\n\n" and exit 255; $in=shift; warn "Error: Can't read input file $in\n" and exit 255 if ! -s $in; } open (INFILE, $in) or die "Can't open $in for reading\n"; while (<INFILE>) { $line = $_; chomp $line; @character=split /\.*/; while (@character){ my $character = shift @character; $ord = ord($character); if ($ord>126) { print "$in contains illegal character \(ord:\ ", "$ord\) on line + $."; } elsif ($ord<32) { if ($ord<9) { print "$in contains illegal character \(ord:\ ", "$ord\) on li +ne $."; } if ($ord>10) { print "$in contains illegal character \(ord:\ ", "$ord\) on li +ne $."; } } } } close (INFILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Rogue Null (ordinate 0) characters in text files
by ikegami (Patriarch) on May 07, 2008 at 23:56 UTC | |
by almut (Canon) on May 08, 2008 at 00:57 UTC | |
by Thelonius (Priest) on May 08, 2008 at 01:14 UTC | |
by almut (Canon) on May 08, 2008 at 01:48 UTC | |
|
Re: Rogue Null (ordinate 0) characters in text files
by tachyon-II (Chaplain) on May 08, 2008 at 00:39 UTC | |
|
Re: Rogue Null (ordinate 0) characters in text files
by pc88mxer (Vicar) on May 07, 2008 at 23:37 UTC | |
by paulnovl (Novice) on May 08, 2008 at 07:18 UTC |