in reply to Re^2: ASCII insert after read
in thread ASCII insert after read

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.

Replies are listed 'Best First'.
Re^4: ASCII insert after read
by monkjeff (Initiate) on Jul 30, 2008 at 14:16 UTC
    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.
Re^4: ASCII insert after read
by Anonymous Monk on Jul 30, 2008 at 18:26 UTC
    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();
      $hash->{$i} = printf("$line %d",$_);

      This line seems so wrong to me. printf prints something to STDOUT, and returns 1 on success. So this will basically store 1 in $hash->{$i}. Also the hash keys are always numerical - why use a hash at all? An array seems much more appropriate, and easier to handle.

      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>";

      Programming is mostly having the computer do the boring repetitions for you. No need for something like this, you have loops in Perl.

      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.

      If you don't tell me what "wrong" means to you I can't help you.

      The output does contain a 014 character, but if you view it in a browser I guess you don't see it. hexdump is very well suited to inspect the output.