home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixcmds_1 / BIN / tr < prev    next >
Encoding:
Text File  |  1993-06-10  |  573 b   |  26 lines

  1. # Perl version of tr.
  2. # Usage : tr pattern1 pattern2
  3. # Uses stdin to get data.
  4.  
  5. # Get opts into one big string. Assumes all opts precede all args.
  6. while (substr($ARGV[0], 0, 1) eq "-")
  7. {
  8.     $opt = $opt.(shift);
  9. }
  10. $opt =~ s/-//g;
  11.  
  12. die "Usage : tr [-cds] pattern1 pattern2\n" unless (($#ARGV == 1) ||
  13.                                 (index($opt, "d") > -1));
  14.  
  15. # Get the patterns. (Doesn't handle space characters properly)
  16. # Though you can use \040
  17. $from = $ARGV[0];
  18. $to   = $ARGV[1] || "";
  19.  
  20. # For each line of stdin, do the transform.
  21. while (<STDIN>)
  22. {
  23.     eval("tr/$from/$to/$opt");
  24.     print;
  25. }
  26.