using tr and ascii value

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default using tr and ascii value

    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);
    Dan Guzman Guest

  2. Similar Questions and Discussions

    1. Non Ascii pathname
      When I try to open a .dcr file that has Japanese characters in the pathname IE seems to find it fine. But the ActiveX control seems to be unable to...
    2. ASCII bug?
      mysql field.test="St. Patrick’s Day " ------------------------ form.cfm: <cfquery name="getfield" datasource="database"> select field from...
    3. string to ascii
      let's say I have a string say, "abcABC" how do I convert those 6 letters into their respective ASCII numbers, and if I have 6 ASCII numbers, how...
    4. Ascii to tif.
      AIX version 4.3.3 computer rs6000/f50 Is there a AIX/UNIX utility that will take an ASCII file and convert it to a TIF file?
  3. #2

    Default Re: using tr and ascii value

    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.

    ....


    --
    Bob Walton

    Bob Walton Guest

  4. #3

    Default Re: using tr and ascii value

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

    [email]dan@danguzman.com[/email] (Dan Guzman) wrote in
    news:ddf15003.0308061646.6c037d1f@posting.google.c om:
    > 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/AwUBPzGtZmPeouIeTNHoEQJUIQCfbvVcljOeyDKYYJ7V7hua0Q 3Z9V4AoLcB
    5lHA8bKsv7MgaACKJorxqX1T
    =PiEV
    -----END PGP SIGNATURE-----
    Eric J. Roode Guest

  5. #4

    Default Re: using tr and ascii value

    [email]tadmc@augustmail.com[/email] (Tad McClellan) wrote in message news:<slrnbj3gf7.2e2.tadmc@magna.augustmail.com>.. .
    > Dan Guzman <dan@danguzman.com> wrote:
    >
    > > I'm updating a process that reads in text file from a mainframe
    > > extract.
    >
    >
    > What OS is your Perl program running on?
    >
    The OS is Windows 2000. Running ActivePerl build 626
    >
    > > I'm having a problem when the mainframe put
    > > in a certain character ' ' the perl script stops running.
    >
    I'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
    Dan Guzman Guest

  6. #5

    Default Re: using tr and ascii value

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

    [email]dan@danguzman.com[/email] (Dan Guzman) wrote in
    news:ddf15003.0308070727.4a8f32e1@posting.google.c om:
    > 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+OHqm7zm3 pqCxoAnji/
    egxse58hwqS0hQHgwDtXWii4
    =cTON
    -----END PGP SIGNATURE-----
    Eric J. Roode Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139