using tr and ascii value

D

Dan Guzman

I'm updating a process that reads in text file from a mainframe
extract. The script reads and parses out this file and creates html
documents from this data. I'm having a problem when the mainframe put
in a certain character '' the perl script stops running. It's values
are:

hex - 1a
dec - 26
oct - 032

How do I replace these types of characters? Thanks,

Dan
.........

while($mLine=<INPUTFILE>) {
chomp($mLine);
$mLine =~tr/<>/ /; #-replaces <> with a space .
$mLine =~tr/\26/ /;
print $mLine;

if (substr($mLine,0,12) eq "START-REC!!!") {
#- Parse columns and insert to table!
($mTag,$mticket) = split /!!!/,$mLine;
$mticket=~ s/^\s*(.*?)\s*$/$1/;

$mText = "<pre><b><font size=4 color=blue>Ticket :
$mticket</font>\n<font size=1 color=blue>Last Mainframe
Synchronization: $mLastUpdate</font>\n\n</b>";

} elsif (substr($mLine,0,13) eq "!!!END-REC!!!") {

$mText=$mText."\n<b><font size=1 color=blue>Last Mainframe
Synchronization: $mLastUpdate</font></b></pre>";

#- Write $mText to file using the ticket nnumber as filename.
&loadTicketData($mticket,$mText);
print "$mticket\n";

} else {
$mText=$mText.$mLine."\n";

}
}
close(INPUTFILE);
 
B

Bob Walton

Dan Guzman wrote:

....
hex - 1a
dec - 26
oct - 032

How do I replace these types of characters? Thanks,

Dan ....


$mLine =~tr/\26/ /;


Did you look in the docs, specifically:

perldoc perlop

? There it will tell you that something like:

$mLine =~ tr/\032/ /;

or

$mLine =~ tr/\x1a/ /;

should work.

....
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (Dan Guzman) wrote in
I'm updating a process that reads in text file from a mainframe
extract. The script reads and parses out this file and creates html
documents from this data. I'm having a problem when the mainframe put
in a certain character '' the perl script stops running. It's values
are:

hex - 1a
dec - 26
oct - 032

How do I replace these types of characters? Thanks,
........
$mLine =~tr/\26/ /;

Close. Backslash-escaping doesn't work in decimal. You can either use
octal:
$mLine =~ tr/\032/ /;
or hex:
$mLine =~ tr/\x1a/ /;
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzGtZmPeouIeTNHoEQJUIQCfbvVcljOeyDKYYJ7V7hua0Q3Z9V4AoLcB
5lHA8bKsv7MgaACKJorxqX1T
=PiEV
-----END PGP SIGNATURE-----
 
D

Dan Guzman

What OS is your Perl program running on?
The OS is Windows 2000. Running ActivePerl build 626I've tried the suggestions above, but without success:

$mLine =~ tr/\x1a/ /;
$mLine =~ tr/\032/ /;
If your program is running on an OS whose filesystem makes
a distinction between "text" and "binary" files (like Windows),
then:
Do you mean when the file gets picked up?

$ftp->login($_user,$_passw);
$ftp->ascii();

perldoc -f binmode

might fix it.

Would I do the binmode when I read the file? Thanks,

Dan
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (Dan Guzman) wrote in
I've tried the suggestions above, but without success:

$mLine =~ tr/\x1a/ /;
$mLine =~ tr/\032/ /;

Oh? What was the failure? What did it do that you didn't expect, or what
didn't it do that you did expect? What was your input, your expected
output, and your actual output?

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPzLnaGPeouIeTNHoEQIAcgCgthwYom1PgNmNx+OHqm7zm3pqCxoAnji/
egxse58hwqS0hQHgwDtXWii4
=cTON
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,122
Messages
2,570,715
Members
47,282
Latest member
hopkins1988

Latest Threads

Top