in reply to Searching for control characters

Check that the open succeeded with open X, '>', 'memo.txt_error' or die "Open output file failed: $!"; (the three parameter version of open is preferred).

ord is the function you want rather than ORD - case is important in Perl.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Searching for control characters
by ericdp (Novice) on Feb 07, 2006 at 22:10 UTC
    Thanks much for the help. it does work.
    #!/usr/bin/perl use strict; use warnings; open F, '<', 'notes.txt_error' or die "Open output file failed: $!"; my $row; my $line; $row = 0; while (<F>) { chomp; $line = $_; $row++; if ( $line =~ /([[:cntrl:]])/ ) { my $c = $1; printf "%u : ||%s||\n", $row, $line; printf "\t : ||%s||\n", ord ($c); print "---------------------------"; } } close F;
    produces
    150 : || <long line> ||
             : ||3||
    ---------------------------
    206 : || <long line> ||
             : ||9||
    ---------------------------
    317 : || <long line> ||
             : ||28||
    ---------------------------
    12878 : || <long line> ||
             : ||24||
    ---------------------------
    
    Now to find out how these odd control characters got into my data. But that is a different story.
    Thanks much. Eric