home *** CD-ROM | disk | FTP | other *** search
- # Perl version of tr.
- # Usage : tr pattern1 pattern2
- # Uses stdin to get data.
-
- # Get opts into one big string. Assumes all opts precede all args.
- while (substr($ARGV[0], 0, 1) eq "-")
- {
- $opt = $opt.(shift);
- }
- $opt =~ s/-//g;
-
- die "Usage : tr [-cds] pattern1 pattern2\n" unless (($#ARGV == 1) ||
- (index($opt, "d") > -1));
-
- # Get the patterns. (Doesn't handle space characters properly)
- # Though you can use \040
- $from = $ARGV[0];
- $to = $ARGV[1] || "";
-
- # For each line of stdin, do the transform.
- while (<STDIN>)
- {
- eval("tr/$from/$to/$opt");
- print;
- }
-