in reply to Re^3: ASCII insert after read
in thread ASCII insert after read
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 code999999999999 + XXXXXXXXXX
#!/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();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: ASCII insert after read
by moritz (Cardinal) on Jul 30, 2008 at 18:41 UTC |