in reply to ASCII insert after read

open(INFO, "testdoc.txt");

Always check for the success of your open:

open INFO, '<', 'testdoc.txt' or die "Can't open testdoc.txt: $!";

That way you won't get bad surprises if the file is not available.

for (split//,$line) { $test = sprintf "\%3o\n", ord $_; if ($test == 14) {

That's a really odd way to test if a certain character appears in a line. What about this one?

my $char = chr oct 14; while (my $line = <INFO>){ if ($line =~ m/\Q$char\E/){ # do whatever you want } }

You might also take a look at index.

Replies are listed 'Best First'.
Re^2: ASCII insert after read
by monkjeff (Initiate) on Jul 30, 2008 at 13:12 UTC
    so how do I get that to print out. For some reason I cannot get it to show up on the output.
      Could you please be more specific? What do you want to show up in the output, and what do you expect?

      It would help if you could provide a small script along with some sample input data and your desired output. Then we can help you better.

        sure, I am actually trying to get the ASCII character to show up at the end of line. I can visually see it and with code I can identify it however when I got to printing out the value to an output file, the same character doesn't show up at the end of the line. Much thanks for your help.
        Sample Text
        999999999999 + XXXXXXXXXX
        When I read in the text line by line, I can check for the 014 shift out ASCII character however when I use the print OUT $line the ASCII character is wrong. here is my code
        #!/usr/bin/perl use CGI qw(:standard); open(INFO, "testdoc.txt"); print header(); print start_html(); my @record; my %hash; my $true = 0; $i =0; my $FEI; my $pack; ($sec,$min,$hour,$mday,$mon,$year,$wday, $yday,$isdst)=localtime(time); #printf "%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900,$mon+1,$mday,$hou +r,$min,$sec; open (OUT, '>OUTPUT.txt'); while ($line = <INFO>){ # print $line . "<BR>"; #check each character of the line for a page break for (split//,$line) { $test = sprintf "\%3o\n", ord $_; if ($test == 14) { # WE HAVE FOUND A NEW PAGE $true = 1; $hash->{$i} = printf("$line %d",$_); $i++; # store next 8 lines in a hash } } if ($true == 1){ $hash->{$i} = $line; print $hash->{i} . "<br>"; if ($i == 9){ if ($hash->{9} =~ /4\d{8}/ig) { $hash->{2} = " + Heart Hospital\n"; } if ($hash->{2} =~ /Heart Hospital/){ $FEI = $hash->{6}; #print $FEI . "<br>"; switch the F +EI to what Doris recommends $FEI =~ s/350593390/261766835/; $hash->{6} = $FEI; } #print OUT $hash->{1};# . "\n"; print OUT $hash->{2};# . "\n"; print OUT $hash->{3};# . "\n"; print OUT $hash->{4};# . "\n"; print OUT $hash->{5};# . "\n"; print OUT $hash->{6};# . "\n"; print OUT $hash->{7};# . "\n"; print OUT $hash->{8};# . "\n"; print OUT $hash->{9};# . "\n"; #print $hash->{1} . "1<br>"; print $hash->{2} . "2<br>"; print $hash->{3} . "3<br>"; print $hash->{4} . "4<br>"; print $hash->{5} . "5<br>"; print $hash->{6} . "6<br>"; print $hash->{7} . "7<br>"; print $hash->{8} . "8<br>"; print $hash->{9} . "9<br>"; $i=0; $true=0; $hash->{1} = ""; $hash->{2} = ""; $hash->{3} = ""; $hash->{4} = ""; $hash->{5} = ""; $hash->{6} = ""; $hash->{7} = ""; $hash->{8} = ""; $hash->{9} = ""; } elsif ($line =~/TOTALS/){ print OUT $line; } elsif ($line =~/END OF REPORT/){ print OUT $line; } else { $i++ } }else{ print OUT $line } } #end while close OUT; print end_html();