[comp.lang.perl] tr/// cannot translate to chars whose codes are greater than 127

ishii@hexard.co.jp (Koji Ishii) (10/31/90)

     Tested on perl3.0.37 on Sun4 (OS4.0.3c),

tr/\000-\177/\200-\377/;

does nothing.  In scantrans() in toke.c, characters are assigned to
signed char, and then to signed short, extending sign.  Generated
table is checked in do_trans() in doarg.c whether it is less than 0,
so all translations are ignored.

  Following patch will fix problem.

*** toke.c.orig	Wed Oct 31 17:03:40 1990
--- toke.c	Wed Oct 31 17:07:53 1990
***************
*** 1906,1912 ****
  		    }
  		    --j;
  		}
! 		tbl[i] = r[j];
  	    }
  	}
      }
--- 1906,1912 ----
  		    }
  		    --j;
  		}
! 		tbl[i] = r[j] & 0377;
  	    }
  	}
      }
***************
*** 1923,1929 ****
  		--j;
  	    }
  	    if (tbl[t[i] & 0377] == -1)
! 		tbl[t[i] & 0377] = r[j];
  	}
      }
      if (r != t)
--- 1923,1929 ----
  		--j;
  	    }
  	    if (tbl[t[i] & 0377] == -1)
! 		tbl[t[i] & 0377] = r[j] & 0377;
  	}
      }
      if (r != t)
--
----------------------------------
   Koji Ishii  Hexard Inc., Tokyo, Japan.     JUNET: ishii@hexard.co.jp